<s>
SYN	B-Protocol
cookie	I-Protocol
is	O
a	O
technique	O
used	O
to	O
resist	O
SYN	O
flood	O
attacks	O
.	O
</s>
<s>
The	O
technique	O
's	O
primary	O
inventor	O
Daniel	O
J	O
.	O
Bernstein	O
defines	O
SYN	B-Protocol
cookies	I-Protocol
as	O
"	O
particular	O
choices	O
of	O
initial	O
TCP	B-Protocol
sequence	B-Protocol
numbers	I-Protocol
by	O
TCP	B-Protocol
servers.	O
"	O
</s>
<s>
In	O
particular	O
,	O
the	O
use	O
of	O
SYN	B-Protocol
cookies	I-Protocol
allows	O
a	O
server	O
to	O
avoid	O
dropping	O
connections	O
when	O
the	O
SYN	O
queue	O
fills	O
up	O
.	O
</s>
<s>
Instead	O
of	O
storing	O
additional	O
connections	O
,	O
a	O
SYN	O
queue	O
entry	O
is	O
encoded	O
into	O
the	O
sequence	B-Protocol
number	I-Protocol
sent	O
in	O
the	O
SYN+ACK	O
response	O
.	O
</s>
<s>
If	O
the	O
server	O
then	O
receives	O
a	O
subsequent	O
ACK	O
response	O
from	O
the	O
client	O
with	O
the	O
incremented	O
sequence	B-Protocol
number	I-Protocol
,	O
the	O
server	O
is	O
able	O
to	O
reconstruct	O
the	O
SYN	O
queue	O
entry	O
using	O
information	O
encoded	O
in	O
the	O
TCP	B-Protocol
sequence	B-Protocol
number	I-Protocol
and	O
proceed	O
as	O
usual	O
with	O
the	O
connection	O
.	O
</s>
<s>
In	O
order	O
to	O
initiate	O
a	O
TCP	B-Protocol
connection	O
,	O
the	O
client	O
sends	O
a	O
TCP	B-Protocol
SYN	B-Protocol
packet	I-Protocol
to	O
the	O
server	O
.	O
</s>
<s>
In	O
response	O
,	O
the	O
server	O
sends	O
a	O
TCP	B-Protocol
SYN+ACK	O
packet	O
back	O
to	O
the	O
client	O
.	O
</s>
<s>
One	O
of	O
the	O
values	O
in	O
this	O
packet	O
is	O
a	O
sequence	B-Protocol
number	I-Protocol
,	O
which	O
is	O
used	O
by	O
the	O
TCP	B-Protocol
to	O
reassemble	O
the	O
data	O
stream	O
.	O
</s>
<s>
According	O
to	O
the	O
TCP	B-Protocol
specification	O
,	O
that	O
first	O
sequence	B-Protocol
number	I-Protocol
sent	O
by	O
an	O
endpoint	O
can	O
be	O
any	O
value	O
as	O
decided	O
by	O
that	O
endpoint	O
.	O
</s>
<s>
As	O
the	O
sequence	B-Protocol
number	I-Protocol
is	O
chosen	O
by	O
the	O
sender	O
,	O
returned	O
by	O
the	O
recipient	O
,	O
and	O
has	O
no	O
otherwise-defined	O
internal	O
structure	O
,	O
it	O
can	O
be	O
overloaded	O
to	O
carry	O
additional	O
data	O
.	O
</s>
<s>
The	O
following	O
describes	O
one	O
possible	O
implementation	O
,	O
however	O
as	O
there	O
is	O
no	O
public	O
standard	O
to	O
follow	O
,	O
the	O
order	O
,	O
length	O
,	O
and	O
semantics	O
of	O
the	O
fields	O
may	O
differ	O
between	O
SYN	B-Protocol
cookie	I-Protocol
implementations	O
.	O
</s>
<s>
SYN	B-Protocol
cookies	I-Protocol
are	O
initial	O
sequence	B-Protocol
numbers	I-Protocol
that	O
are	O
carefully	O
constructed	O
according	O
to	O
the	O
following	O
rules	O
:	O
</s>
<s>
The	O
initial	O
TCP	B-Protocol
sequence	B-Protocol
number	I-Protocol
,	O
i.e.	O
</s>
<s>
the	O
SYN	B-Protocol
cookie	I-Protocol
,	O
is	O
computed	O
as	O
follows	O
:	O
</s>
<s>
(	O
Note	O
:	O
since	O
m	O
must	O
be	O
encoded	O
using	O
3	O
bits	O
,	O
the	O
server	O
is	O
restricted	O
to	O
sending	O
up	O
to	O
8	O
unique	O
values	O
for	O
m	O
when	O
SYN	B-Protocol
cookies	I-Protocol
are	O
in	O
use	O
.	O
)	O
</s>
<s>
When	O
a	O
client	O
sends	O
back	O
a	O
TCP	B-Protocol
ACK	B-Protocol
packet	I-Protocol
to	O
the	O
server	O
in	O
response	O
to	O
the	O
server	O
's	O
SYN+ACK	O
packet	O
,	O
the	O
client	O
must	O
(	O
according	O
to	O
the	O
TCP	B-Protocol
spec	O
)	O
use	O
n+1	O
in	O
the	O
packet	O
's	O
Acknowledgement	O
number	O
,	O
where	O
n	O
is	O
the	O
initial	O
sequence	B-Protocol
number	I-Protocol
sent	O
by	O
the	O
server	O
.	O
</s>
<s>
The	O
server	O
then	O
subtracts	O
1	O
from	O
the	O
acknowledgement	O
number	O
to	O
reveal	O
the	O
SYN	B-Protocol
cookie	I-Protocol
sent	O
to	O
the	O
client	O
.	O
</s>
<s>
Recomputes	O
s	O
to	O
determine	O
whether	O
this	O
is	O
,	O
indeed	O
,	O
a	O
valid	O
SYN	B-Protocol
cookie	I-Protocol
.	O
</s>
<s>
Decodes	O
the	O
value	O
m	O
from	O
the	O
3-bit	O
encoding	O
in	O
the	O
SYN	B-Protocol
cookie	I-Protocol
,	O
which	O
it	O
then	O
can	O
use	O
to	O
reconstruct	O
the	O
SYN	O
queue	O
entry	O
.	O
</s>
<s>
The	O
use	O
of	O
SYN	B-Protocol
cookies	I-Protocol
does	O
not	O
break	O
any	O
protocol	O
specifications	O
,	O
and	O
therefore	O
should	O
be	O
compatible	O
with	O
all	O
TCP	B-Protocol
implementations	O
.	O
</s>
<s>
There	O
are	O
,	O
however	O
,	O
two	O
caveats	O
that	O
take	O
effect	O
when	O
SYN	B-Protocol
cookies	I-Protocol
are	O
in	O
use	O
.	O
</s>
<s>
Secondly	O
,	O
early	O
implementations	O
rejected	O
all	O
TCP	B-Protocol
options	O
(	O
such	O
as	O
large	O
windows	O
or	O
timestamps	O
)	O
,	O
because	O
the	O
server	O
discarded	O
the	O
SYN	O
queue	O
entry	O
where	O
that	O
information	O
would	O
otherwise	O
be	O
stored	O
.	O
</s>
<s>
;	O
however	O
v2.6.26	O
of	O
the	O
Linux	B-Operating_System
kernel	I-Operating_System
added	O
partial	O
support	O
of	O
TCP	B-Protocol
options	O
by	O
encoding	O
them	O
into	O
the	O
timestamp	O
option	O
.	O
</s>
<s>
Finally	O
,	O
SYN	B-Protocol
cookies	I-Protocol
place	O
increased	O
load	O
on	O
server	O
resources	O
.	O
</s>
<s>
The	O
SYN	B-Protocol
cookie	I-Protocol
does	O
not	O
reduce	O
traffic	O
,	O
which	O
makes	O
it	O
ineffective	O
against	O
SYN	O
flooding	O
attacks	O
that	O
target	O
bandwidth	O
as	O
the	O
attack	O
vector	O
.	O
</s>
<s>
In	O
such	O
a	O
situation	O
,	O
the	O
loss	O
of	O
the	O
TCP	B-Protocol
options	O
in	O
order	O
to	O
save	O
the	O
connection	O
is	O
usually	O
considered	O
to	O
be	O
a	O
reasonable	O
compromise	O
.	O
</s>
<s>
A	O
problem	O
arises	O
when	O
the	O
connection-finalizing	O
ACK	B-Protocol
packet	I-Protocol
sent	O
by	O
the	O
client	O
is	O
lost	O
,	O
and	O
the	O
application	O
layer	O
protocol	O
requires	O
the	O
server	O
to	O
speak	O
first	O
(	O
SMTP	B-Protocol
and	O
SSH	B-Protocol
are	O
two	O
examples	O
)	O
.	O
</s>
<s>
TCP	B-Protocol
Cookie	I-Protocol
Transactions	I-Protocol
(	O
TCPCT	B-Protocol
)	O
standard	O
was	O
designed	O
to	O
overcome	O
these	O
shortcomings	O
of	O
SYN	B-Protocol
cookies	I-Protocol
and	O
improve	O
it	O
on	O
a	O
couple	O
of	O
aspects	O
.	O
</s>
<s>
Unlike	O
SYN	B-Protocol
cookies	I-Protocol
,	O
TCPCT	B-Protocol
is	O
a	O
TCP	B-Protocol
extension	O
and	O
required	O
support	O
from	O
both	O
endpoints	O
.	O
</s>
<s>
Simple	O
firewalls	B-Application
that	O
are	O
configured	O
to	O
allow	O
all	O
outgoing	O
connections	O
but	O
to	O
restrict	O
which	O
ports	O
an	O
incoming	O
connection	O
can	O
reach	O
(	O
for	O
example	O
,	O
allow	O
incoming	O
connections	O
to	O
a	O
Web	O
server	O
on	O
port	O
80	O
but	O
restrict	O
all	O
other	O
ports	O
)	O
,	O
work	O
by	O
blocking	O
only	O
incoming	O
SYN	O
requests	O
to	O
unwanted	O
ports	O
.	O
</s>
<s>
If	O
SYN	B-Protocol
cookies	I-Protocol
are	O
in	O
operation	O
,	O
care	O
should	O
be	O
taken	O
to	O
ensure	O
an	O
attacker	O
is	O
not	O
able	O
to	O
bypass	O
such	O
a	O
firewall	B-Application
by	O
forging	O
ACKs	O
instead	O
,	O
trying	O
random	O
sequence	B-Protocol
numbers	I-Protocol
until	O
one	O
is	O
accepted	O
.	O
</s>
<s>
SYN	B-Protocol
cookies	I-Protocol
should	O
be	O
switched	O
on	O
and	O
off	O
on	O
a	O
per-port	O
basis	O
,	O
so	O
that	O
SYN	B-Protocol
cookies	I-Protocol
being	O
enabled	O
on	O
a	O
public	O
port	O
does	O
not	O
cause	O
them	O
to	O
be	O
recognised	O
on	O
a	O
non-public	O
port	O
.	O
</s>
<s>
The	O
original	O
Linux	B-Operating_System
kernel	I-Operating_System
implementation	O
misunderstood	O
this	O
part	O
of	O
Bernstein	O
's	O
description	O
and	O
used	O
a	O
single	O
global	O
variable	O
to	O
switch	O
on	O
SYN	B-Protocol
cookies	I-Protocol
for	O
all	O
ports	O
;	O
this	O
was	O
pointed	O
out	O
by	O
a	O
research	O
student	O
and	O
subsequently	O
fixed	O
in	O
.	O
</s>
<s>
The	O
first	O
implementation	O
(	O
for	O
SunOS	B-Operating_System
)	O
was	O
released	O
by	O
Jeff	O
Weisberg	O
a	O
month	O
later	O
,	O
and	O
Eric	O
Schenk	O
released	O
his	O
Linux	B-Application
implementation	O
in	O
February	O
1997	O
.	O
</s>
<s>
FreeBSD	B-Operating_System
implements	O
syncookies	B-Protocol
since	O
FreeBSD	B-Operating_System
4.5	O
(	O
January	O
2002	O
)	O
.	O
</s>
