Date: Mon, 8 Sep 2025 22:02:37 GMT From: Michael Tuexen <tuexen@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 5d65c9eeb805 - stable/14 - tcp: micro-optimize SYN-cookie expansion Message-ID: <202509082202.588M2bY0028858@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=5d65c9eeb8057ac796cf9b51ab3fa3d30b06e91c commit 5d65c9eeb8057ac796cf9b51ab3fa3d30b06e91c Author: Michael Tuexen <tuexen@FreeBSD.org> AuthorDate: 2025-09-01 22:18:35 +0000 Commit: Michael Tuexen <tuexen@FreeBSD.org> CommitDate: 2025-09-08 21:57:11 +0000 tcp: micro-optimize SYN-cookie expansion Only compute wscale when it is actually used. While there, change the type of wscale to u_int as suggested by glebius. No functional change intended. Reviewed by: glebius, rscheff (older version) Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D52296 (cherry picked from commit 341d1aabc13e47911d2eb38e857b90f7d356134e) --- sys/netinet/tcp_syncache.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index 5a12aa3ed21a..29dbaaec929a 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1672,7 +1672,7 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, sc->sc_tsoff = tcp_new_ts_offset(inc); } if ((to->to_flags & TOF_SCALE) && (V_tcp_do_rfc1323 != 3)) { - int wscale = 0; + u_int wscale = 0; /* * Pick the smallest possible scaling factor that @@ -2268,7 +2268,7 @@ syncookie_lookup(struct in_conninfo *inc, struct syncache_head *sch, uint32_t hash; uint8_t *secbits; tcp_seq ack, seq; - int wnd, wscale = 0; + int wnd; union syncookie cookie; /* @@ -2319,12 +2319,14 @@ syncookie_lookup(struct in_conninfo *inc, struct syncache_head *sch, sc->sc_peer_mss = tcp_sc_msstab[cookie.flags.mss_idx]; - /* We can simply recompute receive window scale we sent earlier. */ - while (wscale < TCP_MAX_WINSHIFT && (TCP_MAXWIN << wscale) < sb_max) - wscale++; - /* Only use wscale if it was enabled in the orignal SYN. */ if (cookie.flags.wscale_idx > 0) { + u_int wscale = 0; + + /* Recompute the receive window scale that was sent earlier. */ + while (wscale < TCP_MAX_WINSHIFT && + (TCP_MAXWIN << wscale) < sb_max) + wscale++; sc->sc_requested_r_scale = wscale; sc->sc_requested_s_scale = tcp_sc_wstab[cookie.flags.wscale_idx]; sc->sc_flags |= SCF_WINSCALE;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509082202.588M2bY0028858>