Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Sep 2019 18:48:26 +0000 (UTC)
From:      Andrew Gallatin <gallatin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r352228 - head/sys/netinet
Message-ID:  <201909111848.x8BImQnn056188@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gallatin
Date: Wed Sep 11 18:48:26 2019
New Revision: 352228
URL: https://svnweb.freebsd.org/changeset/base/352228

Log:
  Avoid unneeded call to arc4random() in syncache_add()
  
  Don't call arc4random() unconditionally to initialize sc_iss, and
  then when syncookies are enabled, just overwrite it with the
  return value from from syncookie_generate(). Instead, only call
  arc4random() to initialize sc_iss when syncookies are not
  enabled.
  
  Note that on a system under a syn flood attack, arc4random()
  becomes quite expensive, and the chacha_poly crypto that it calls
  is one of the more expensive things happening on the
  system. Removing this unneeded arc4random() call reduces CPU from
  about 40% to about 35% in my test scenario (Broadwell Xeon, 6Mpps
  syn flood attack).
  
  Reviewed by:	rrs, tuxen, bz
  Sponsored by:	Netflix
  Differential Revision:	https://reviews.freebsd.org/D21591

Modified:
  head/sys/netinet/tcp_syncache.c

Modified: head/sys/netinet/tcp_syncache.c
==============================================================================
--- head/sys/netinet/tcp_syncache.c	Wed Sep 11 18:40:05 2019	(r352227)
+++ head/sys/netinet/tcp_syncache.c	Wed Sep 11 18:48:26 2019	(r352228)
@@ -1543,7 +1543,6 @@ skip_alloc:
 	sc->sc_todctx = todctx;
 #endif
 	sc->sc_irs = th->th_seq;
-	sc->sc_iss = arc4random();
 	sc->sc_flags = 0;
 	sc->sc_flowlabel = 0;
 
@@ -1617,6 +1616,8 @@ skip_alloc:
 
 	if (V_tcp_syncookies)
 		sc->sc_iss = syncookie_generate(sch, sc);
+	else
+		sc->sc_iss = arc4random();
 #ifdef INET6
 	if (autoflowlabel) {
 		if (V_tcp_syncookies)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909111848.x8BImQnn056188>