From c556884f8e7579213622770306adf1457d9d35ae Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Sat, 7 Jul 2018 11:18:26 +0000 Subject: [PATCH] When initializing the TCP FO client cookie cache, take into account whether the TCP FO support is enabled or not for the client side. The code in tcp_fastopen_init() implicitly assumed that the sysctl variable V_tcp_fastopen_client_enable was initialized to 0. This was initially true, but was changed in r335610, which unmasked this bug. Thanks to Pieter de Goeje for reporting the issue on freebsd-net@ --- sys/netinet/tcp_fastopen.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/netinet/tcp_fastopen.c b/sys/netinet/tcp_fastopen.c index 072d67f526de..c7181726fc23 100644 --- a/sys/netinet/tcp_fastopen.c +++ b/sys/netinet/tcp_fastopen.c @@ -408,7 +408,13 @@ tcp_fastopen_init(void) TAILQ_INIT(&V_tcp_fastopen_ccache.base[i].ccb_entries); mtx_init(&V_tcp_fastopen_ccache.base[i].ccb_mtx, "tfo_ccache_bucket", NULL, MTX_DEF); - V_tcp_fastopen_ccache.base[i].ccb_num_entries = -1; /* bucket disabled */ + if (V_tcp_fastopen_client_enable) { + /* enable bucket */ + V_tcp_fastopen_ccache.base[i].ccb_num_entries = 0; + } else { + /* disable bucket */ + V_tcp_fastopen_ccache.base[i].ccb_num_entries = -1; + } V_tcp_fastopen_ccache.base[i].ccb_ccache = &V_tcp_fastopen_ccache; } @@ -824,6 +830,9 @@ sysctl_net_inet_tcp_fastopen_client_enable(SYSCTL_HANDLER_ARGS) /* enabled -> disabled */ for (i = 0; i < V_tcp_fastopen_ccache.buckets; i++) { ccb = &V_tcp_fastopen_ccache.base[i]; + KASSERT(ccb->ccb_num_entries > -1, + ("%s: ccb->ccb_num_entries %d is negative", + __func__, ccb->ccb_num_entries)); tcp_fastopen_ccache_bucket_trim(ccb, 0); } V_tcp_fastopen_client_enable = 0;