git: 034a924009bc - main - tcp: Ensure that vnets have an initialized V_default_cc_ptr

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 12 Nov 2021 19:19:12 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=034a924009bc9cab371f6aa1623bc2aa2ea80cc7

commit 034a924009bc9cab371f6aa1623bc2aa2ea80cc7
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-11-12 18:44:12 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2021-11-12 19:18:12 +0000

    tcp: Ensure that vnets have an initialized V_default_cc_ptr
    
    This causes new vnets to inherit the cc algorithm from vnet0. This is a
    temporary patch to fix vnet jail creation.
    
    With encouragement from: glebius
    Fixes: b8d60729deef ("tcp: Congestion control cleanup.")
    Differential Revision: https://reviews.freebsd.org/D32970
---
 sys/netinet/cc/cc.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/sys/netinet/cc/cc.c b/sys/netinet/cc/cc.c
index df0efcac24be..457f5a6e55e1 100644
--- a/sys/netinet/cc/cc.c
+++ b/sys/netinet/cc/cc.c
@@ -316,6 +316,23 @@ cc_register_algo(struct cc_algo *add_cc)
 	return (err);
 }
 
+static void
+vnet_cc_sysinit(void *arg)
+{
+	struct cc_algo *cc;
+
+	if (IS_DEFAULT_VNET(curvnet))
+		return;
+
+	CURVNET_SET(vnet0);
+	cc = V_default_cc_ptr;
+	CURVNET_RESTORE();
+
+	V_default_cc_ptr = cc;
+}
+VNET_SYSINIT(vnet_cc_sysinit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY,
+    vnet_cc_sysinit, NULL);
+
 /*
  * Perform any necessary tasks before we exit congestion recovery.
  */