OSDN Git Service

tcp: add small random increments to the source port
authorWilly Tarreau <w@1wt.eu>
Mon, 2 May 2022 08:46:11 +0000 (10:46 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 5 May 2022 02:22:21 +0000 (19:22 -0700)
commitca7af0402550f9a0b3316d5f1c30904e42ed257d
treea60a76ce0c77cc4e02ae9287204228c269bed2d1
parent4dfa9b438ee34caca4e6a4e5e961641807367f6f
tcp: add small random increments to the source port

Here we're randomly adding between 0 and 7 random increments to the
selected source port in order to add some noise in the source port
selection that will make the next port less predictable.

With the default port range of 32768-60999 this means a worst case
reuse scenario of 14116/8=1764 connections between two consecutive
uses of the same port, with an average of 14116/4.5=3137. This code
was stressed at more than 800000 connections per second to a fixed
target with all connections closed by the client using RSTs (worst
condition) and only 2 connections failed among 13 billion, despite
the hash being reseeded every 10 seconds, indicating a perfectly
safe situation.

Cc: Moshe Kol <moshe.kol@mail.huji.ac.il>
Cc: Yossi Gilad <yossi.gilad@mail.huji.ac.il>
Cc: Amit Klein <aksecurity@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/inet_hashtables.c