From nobody Mon Jan 03 18:22:53 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E6AF7191D3AE; Mon, 3 Jan 2022 18:22:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JSPHd4lVPz3Dyh; Mon, 3 Jan 2022 18:22:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8273121E0; Mon, 3 Jan 2022 18:22:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 203IMrw7026223; Mon, 3 Jan 2022 18:22:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 203IMrGB026222; Mon, 3 Jan 2022 18:22:53 GMT (envelope-from git) Date: Mon, 3 Jan 2022 18:22:53 GMT Message-Id: <202201031822.203IMrGB026222@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 89128ff3e421 - main - protocols: init with standard SYSINIT(9) or VNET_SYSINIT List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 89128ff3e42196c8b41a3c59f7a2d95c0a4ac0ee Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641234173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=o3TIEGEczerY6E6Ai2GfPAAS3rr5PcZ30R58EpW3yNw=; b=qlizhUcEGOxN0UGPf9MIz0g4dOAHjLbQVjToyO0I4UvSaMMM4OgrGT6EhrUDlDzC7ils6K ze/BEil/uMxnDQi3IiGYuOd/TU5bRTsVl1t0vwr/gzVoTaEN8v3btP7gyF+WtrLYqRetK3 a+ecAYE59BK4Dp+PP1H4B1qpAmdB8lBY9pMlxAfl5HeggEYGiKmmjSZJ6vYcp2i4zxoKd1 lTcx5KYq0QUlx3zx5qfi8qvjO8GwNkWbb0GuObV2EvdnTE25t3GNA4DDRhFH0ab64Ji9eA 8wNHXgGUHAiTNaaSiox8gEiGUhhgPGnqWl2tmE2P3pdPqpFw42VhJH1ui5Ojxg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641234173; a=rsa-sha256; cv=none; b=dnUPT7SBwqxGxXsKkpoMn6uFNtWtPDAL7WiVnv532JSQBHU7iV8xRnvNXDJjzD1dhE3djP NBNPaB+voODsDYBCikp5BGC21ejGrvsJg9V5e0sqLrrKMVcHyU0KEMrrdU/fjd3s2NS7AJ imXmV3EhkYZD+f6TMFVaJ3YbHlJXScrLVtZgN9592dns6RM8w6CdaPVXhkE6PT5M0md4J9 lEFBnWWkEkQb1i0UOfBs+jQZBv6z9jh1Ryy0OEO34w1XGv+oOHtIyDfaMrd5nF+DHqPb6V eY8Cn331/s7Cp+M3BzFYz7lbEN3Awsq/ZipTfGQcbRSwJb6FTvL+GWOA8RDQmA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=89128ff3e42196c8b41a3c59f7a2d95c0a4ac0ee commit 89128ff3e42196c8b41a3c59f7a2d95c0a4ac0ee Author: Gleb Smirnoff AuthorDate: 2022-01-03 18:15:21 +0000 Commit: Gleb Smirnoff CommitDate: 2022-01-03 18:15:21 +0000 protocols: init with standard SYSINIT(9) or VNET_SYSINIT The historical BSD network stack loop that rolls over domains and over protocols has no advantages over more modern SYSINIT(9). While doing the sweep, split global and per-VNET initializers. Getting rid of pr_init allows to achieve several things: o Get rid of ifdef's that protect against double foo_init() when both INET and INET6 are compiled in. o Isolate initializers statically to the module they init. o Makes code easier to understand and maintain. Reviewed by: melifaro Differential revision: https://reviews.freebsd.org/D33537 --- share/man/man9/domain.9 | 3 +- sys/dev/hyperv/hvsock/hv_sock.c | 10 +- sys/dev/hyperv/hvsock/hv_sock.h | 1 - sys/kern/uipc_debug.c | 3 - sys/kern/uipc_domain.c | 13 --- sys/net/raw_cb.h | 1 - sys/net/raw_usrreq.c | 5 +- sys/net/rtsock.c | 1 - .../bluetooth/include/ng_btsocket_hci_raw.h | 1 - sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h | 2 - .../bluetooth/include/ng_btsocket_rfcomm.h | 1 - sys/netgraph/bluetooth/include/ng_btsocket_sco.h | 1 - sys/netgraph/bluetooth/socket/ng_btsocket.c | 5 - .../bluetooth/socket/ng_btsocket_hci_raw.c | 10 +- sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c | 10 +- .../bluetooth/socket/ng_btsocket_l2cap_raw.c | 10 +- sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c | 10 +- sys/netgraph/bluetooth/socket/ng_btsocket_sco.c | 10 +- sys/netinet/in_proto.c | 6 -- sys/netinet/ip_divert.c | 7 +- sys/netinet/ip_input.c | 29 +++--- sys/netinet/ip_var.h | 2 - sys/netinet/raw_ip.c | 5 +- sys/netinet/sctp_module.c | 2 - sys/netinet/sctp_usrreq.c | 5 +- sys/netinet/sctp_var.h | 1 - sys/netinet/tcp_subr.c | 104 +++++++++++---------- sys/netinet/tcp_var.h | 1 - sys/netinet/udp_usrreq.c | 11 +-- sys/netinet/udp_var.h | 2 - sys/netinet6/in6_proto.c | 12 --- sys/netinet6/ip6_input.c | 27 +++--- sys/netinet6/ip6_var.h | 1 - sys/netipsec/keysock.c | 1 - sys/sys/protosw.h | 3 - 35 files changed, 126 insertions(+), 190 deletions(-) diff --git a/share/man/man9/domain.9 b/share/man/man9/domain.9 index 03e83edfc14b..867cfa104718 100644 --- a/share/man/man9/domain.9 +++ b/share/man/man9/domain.9 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 13, 2021 +.Dd December 27, 2021 .Dt DOMAIN 9 .Os .Sh NAME @@ -106,7 +106,6 @@ struct protosw { pr_ctlinput_t *pr_ctlinput; /* control input (from below) */ pr_ctloutput_t *pr_ctloutput; /* control output (from above) */ /* utility hooks */ - pr_init_t *pr_init; pr_fasttimo_t *pr_fasttimo; /* fast timeout (200ms) */ pr_slowtimo_t *pr_slowtimo; /* slow timeout (500ms) */ pr_drain_t *pr_drain; /* flush any excess space possible */ diff --git a/sys/dev/hyperv/hvsock/hv_sock.c b/sys/dev/hyperv/hvsock/hv_sock.c index 6d5ad4fc6609..b2a84befafa2 100644 --- a/sys/dev/hyperv/hvsock/hv_sock.c +++ b/sys/dev/hyperv/hvsock/hv_sock.c @@ -118,7 +118,6 @@ static struct protosw hv_socket_protosw[] = { .pr_domain = &hv_socket_domain, .pr_protocol = HYPERV_SOCK_PROTO_TRANS, .pr_flags = PR_CONNREQUIRED, - .pr_init = hvs_trans_init, .pr_usrreqs = &hvs_trans_usrreqs, }, }; @@ -336,12 +335,9 @@ hvs_dom_probe(void) return (0); } -void -hvs_trans_init(void) +static void +hvs_trans_init(void *arg __unused) { - /* Skip initialization of globals for non-default instances. */ - if (!IS_DEFAULT_VNET(curvnet)) - return; HVSOCK_DBG(HVSOCK_DBG_VERBOSE, "%s: HyperV Socket hvs_trans_init called\n", __func__); @@ -354,6 +350,8 @@ hvs_trans_init(void) LIST_INIT(&hvs_trans_bound_socks); LIST_INIT(&hvs_trans_connected_socks); } +SYSINIT(hvs_trans_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, + hvs_trans_init, NULL); /* * Called in two cases: diff --git a/sys/dev/hyperv/hvsock/hv_sock.h b/sys/dev/hyperv/hvsock/hv_sock.h index 877425968345..a1cfc31f6d74 100644 --- a/sys/dev/hyperv/hvsock/hv_sock.h +++ b/sys/dev/hyperv/hvsock/hv_sock.h @@ -96,7 +96,6 @@ struct hvs_pcb { ((struct socket *)((hvspcb)->so)) void hvs_addr_init(struct sockaddr_hvs *, const struct hyperv_guid *); -void hvs_trans_init(void); void hvs_trans_close(struct socket *); void hvs_trans_detach(struct socket *); void hvs_trans_abort(struct socket *); diff --git a/sys/kern/uipc_debug.c b/sys/kern/uipc_debug.c index 76620477fab5..86c3199a3c26 100644 --- a/sys/kern/uipc_debug.c +++ b/sys/kern/uipc_debug.c @@ -330,10 +330,7 @@ db_print_protosw(struct protosw *pr, const char *prname, int indent) db_printf("pr_input: %p ", pr->pr_input); db_printf("pr_output: %p ", pr->pr_output); db_printf("pr_ctlinput: %p\n", pr->pr_ctlinput); - - db_print_indent(indent); db_printf("pr_ctloutput: %p ", pr->pr_ctloutput); - db_printf("pr_init: %p\n", pr->pr_init); db_print_indent(indent); db_printf("pr_fasttimo: %p ", pr->pr_fasttimo); diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c index 9092ff335eb0..200637e00ad8 100644 --- a/sys/kern/uipc_domain.c +++ b/sys/kern/uipc_domain.c @@ -169,8 +169,6 @@ protosw_init(struct protosw *pr) DEFAULT(pu->pru_sopoll, sopoll_generic); DEFAULT(pu->pru_ready, pru_ready_notsupp); #undef DEFAULT - if (pr->pr_init) - (*pr->pr_init)(); } /* @@ -365,7 +363,6 @@ pffindproto(int family, int protocol, int type) int pf_proto_register(int family, struct protosw *npr) { - VNET_ITERATOR_DECL(vnet_iter); struct domain *dp; struct protosw *pr, *fpr; @@ -425,15 +422,6 @@ pf_proto_register(int family, struct protosw *npr) /* Job is done, no more protection required. */ mtx_unlock(&dom_mtx); - /* Initialize and activate the protocol. */ - VNET_LIST_RLOCK(); - VNET_FOREACH(vnet_iter) { - CURVNET_SET_QUIET(vnet_iter); - protosw_init(fpr); - CURVNET_RESTORE(); - } - VNET_LIST_RUNLOCK(); - return (0); } @@ -498,7 +486,6 @@ pf_proto_unregister(int family, int protocol, int type) dpr->pr_output = NULL; dpr->pr_ctlinput = NULL; dpr->pr_ctloutput = NULL; - dpr->pr_init = NULL; dpr->pr_fasttimo = NULL; dpr->pr_slowtimo = NULL; dpr->pr_drain = NULL; diff --git a/sys/net/raw_cb.h b/sys/net/raw_cb.h index bd5e08fc3daa..3356a86d5464 100644 --- a/sys/net/raw_cb.h +++ b/sys/net/raw_cb.h @@ -66,7 +66,6 @@ extern struct mtx rawcb_mtx; * Generic protosw entries for raw socket protocols. */ pr_ctlinput_t raw_ctlinput; -pr_init_t raw_init; /* * Library routines for raw socket usrreq functions; will always be wrapped diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c index 5d4e223e5a0a..f51334cf81fa 100644 --- a/sys/net/raw_usrreq.c +++ b/sys/net/raw_usrreq.c @@ -56,12 +56,13 @@ MTX_SYSINIT(rawcb_mtx, &rawcb_mtx, "rawcb", MTX_DEF); /* * Initialize raw connection block q. */ -void -raw_init(void) +static void +raw_init(void *arg __unused) { LIST_INIT(&V_rawcb_list); } +VNET_SYSINIT(raw_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, raw_init, NULL); /* * Raw protocol input routine. Find the socket associated with the packet(s) diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 6495a4102570..7c4ff01e5e73 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -2691,7 +2691,6 @@ static struct protosw routesw[] = { .pr_flags = PR_ATOMIC|PR_ADDR, .pr_output = route_output, .pr_ctlinput = raw_ctlinput, - .pr_init = raw_init, .pr_usrreqs = &route_usrreqs } }; diff --git a/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h b/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h index 5a51452dc884..21ed3928b5ff 100644 --- a/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h +++ b/sys/netgraph/bluetooth/include/ng_btsocket_hci_raw.h @@ -67,7 +67,6 @@ typedef struct ng_btsocket_hci_raw_pcb * ng_btsocket_hci_raw_pcb_p; #ifdef _KERNEL -void ng_btsocket_hci_raw_init (void); void ng_btsocket_hci_raw_abort (struct socket *); void ng_btsocket_hci_raw_close (struct socket *); int ng_btsocket_hci_raw_attach (struct socket *, int, struct thread *); diff --git a/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h b/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h index 8ecb8821a275..34df9179c860 100644 --- a/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h +++ b/sys/netgraph/bluetooth/include/ng_btsocket_l2cap.h @@ -95,7 +95,6 @@ typedef struct ng_btsocket_l2cap_raw_pcb * ng_btsocket_l2cap_raw_pcb_p; #ifdef _KERNEL -void ng_btsocket_l2cap_raw_init (void); void ng_btsocket_l2cap_raw_abort (struct socket *); void ng_btsocket_l2cap_raw_close (struct socket *); int ng_btsocket_l2cap_raw_attach (struct socket *, int, struct thread *); @@ -191,7 +190,6 @@ typedef struct ng_btsocket_l2cap_pcb * ng_btsocket_l2cap_pcb_p; #ifdef _KERNEL -void ng_btsocket_l2cap_init (void); void ng_btsocket_l2cap_abort (struct socket *); void ng_btsocket_l2cap_close (struct socket *); int ng_btsocket_l2cap_accept (struct socket *, struct sockaddr **); diff --git a/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h b/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h index 569a407ef629..179b6518eb33 100644 --- a/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h +++ b/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h @@ -315,7 +315,6 @@ typedef struct ng_btsocket_rfcomm_pcb * ng_btsocket_rfcomm_pcb_p; #ifdef _KERNEL -void ng_btsocket_rfcomm_init (void); void ng_btsocket_rfcomm_abort (struct socket *); void ng_btsocket_rfcomm_close (struct socket *); int ng_btsocket_rfcomm_accept (struct socket *, struct sockaddr **); diff --git a/sys/netgraph/bluetooth/include/ng_btsocket_sco.h b/sys/netgraph/bluetooth/include/ng_btsocket_sco.h index 979ea408f292..001be86d0a5f 100644 --- a/sys/netgraph/bluetooth/include/ng_btsocket_sco.h +++ b/sys/netgraph/bluetooth/include/ng_btsocket_sco.h @@ -105,7 +105,6 @@ typedef struct ng_btsocket_sco_pcb * ng_btsocket_sco_pcb_p; #ifdef _KERNEL -void ng_btsocket_sco_init (void); void ng_btsocket_sco_abort (struct socket *); void ng_btsocket_sco_close (struct socket *); int ng_btsocket_sco_accept (struct socket *, struct sockaddr **); diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket.c b/sys/netgraph/bluetooth/socket/ng_btsocket.c index fc54154f1274..93866ce79d6c 100644 --- a/sys/netgraph/bluetooth/socket/ng_btsocket.c +++ b/sys/netgraph/bluetooth/socket/ng_btsocket.c @@ -176,7 +176,6 @@ static struct protosw ng_btsocket_protosw[] = { .pr_protocol = BLUETOOTH_PROTO_HCI, .pr_flags = PR_ATOMIC|PR_ADDR, .pr_ctloutput = ng_btsocket_hci_raw_ctloutput, - .pr_init = ng_btsocket_hci_raw_init, .pr_usrreqs = &ng_btsocket_hci_raw_usrreqs, }, { @@ -184,7 +183,6 @@ static struct protosw ng_btsocket_protosw[] = { .pr_domain = &ng_btsocket_domain, .pr_protocol = BLUETOOTH_PROTO_L2CAP, .pr_flags = PR_ATOMIC|PR_ADDR, - .pr_init = ng_btsocket_l2cap_raw_init, .pr_usrreqs = &ng_btsocket_l2cap_raw_usrreqs, }, { @@ -193,7 +191,6 @@ static struct protosw ng_btsocket_protosw[] = { .pr_protocol = BLUETOOTH_PROTO_L2CAP, .pr_flags = PR_ATOMIC|PR_CONNREQUIRED, .pr_ctloutput = ng_btsocket_l2cap_ctloutput, - .pr_init = ng_btsocket_l2cap_init, .pr_usrreqs = &ng_btsocket_l2cap_usrreqs, }, { @@ -202,7 +199,6 @@ static struct protosw ng_btsocket_protosw[] = { .pr_protocol = BLUETOOTH_PROTO_RFCOMM, .pr_flags = PR_CONNREQUIRED, .pr_ctloutput = ng_btsocket_rfcomm_ctloutput, - .pr_init = ng_btsocket_rfcomm_init, .pr_usrreqs = &ng_btsocket_rfcomm_usrreqs, }, { @@ -211,7 +207,6 @@ static struct protosw ng_btsocket_protosw[] = { .pr_protocol = BLUETOOTH_PROTO_SCO, .pr_flags = PR_ATOMIC|PR_CONNREQUIRED, .pr_ctloutput = ng_btsocket_sco_ctloutput, - .pr_init = ng_btsocket_sco_init, .pr_usrreqs = &ng_btsocket_sco_usrreqs, }, }; diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c b/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c index c82515f82631..59bacf8c965b 100644 --- a/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c +++ b/sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c @@ -728,16 +728,12 @@ NG_HCI_OCF(opcode) - 1)) * Initialize everything */ -void -ng_btsocket_hci_raw_init(void) +static void +ng_btsocket_hci_raw_init(void *arg __unused) { bitstr_t *f = NULL; int error = 0; - /* Skip initialization of globals for non-default instances. */ - if (!IS_DEFAULT_VNET(curvnet)) - return; - ng_btsocket_hci_raw_node = NULL; ng_btsocket_hci_raw_debug_level = NG_BTSOCKET_WARN_LEVEL; ng_btsocket_hci_raw_ioctl_timeout = 5; @@ -889,6 +885,8 @@ ng_btsocket_hci_raw_init(void) bit_set(f, NG_HCI_OCF_LE_READ_WHITE_LIST_SIZE - 1); } /* ng_btsocket_hci_raw_init */ +SYSINIT(ng_btsocket_hci_raw_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, + ng_btsocket_hci_raw_init, NULL); /* * Abort connection on socket diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c b/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c index 18d7a89b7a2f..34d1d69f408f 100644 --- a/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c +++ b/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c @@ -1887,15 +1887,11 @@ ng_btsocket_l2cap_rtclean(void *context, int pending) * Initialize everything */ -void -ng_btsocket_l2cap_init(void) +static void +ng_btsocket_l2cap_init(void *arg __unused) { int error = 0; - /* Skip initialization of globals for non-default instances. */ - if (!IS_DEFAULT_VNET(curvnet)) - return; - ng_btsocket_l2cap_node = NULL; ng_btsocket_l2cap_debug_level = NG_BTSOCKET_WARN_LEVEL; @@ -1950,6 +1946,8 @@ ng_btsocket_l2cap_init(void) TASK_INIT(&ng_btsocket_l2cap_rt_task, 0, ng_btsocket_l2cap_rtclean, NULL); } /* ng_btsocket_l2cap_init */ +SYSINIT(ng_btsocket_l2cap_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, + ng_btsocket_l2cap_init, NULL); /* * Abort connection on socket diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c b/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c index 5508ff7526d2..7674c23f25cc 100644 --- a/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c +++ b/sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c @@ -513,15 +513,11 @@ ng_btsocket_l2cap_raw_rtclean(void *context, int pending) * Initialize everything */ -void -ng_btsocket_l2cap_raw_init(void) +static void +ng_btsocket_l2cap_raw_init(void *arg __unused) { int error = 0; - /* Skip initialization of globals for non-default instances. */ - if (!IS_DEFAULT_VNET(curvnet)) - return; - ng_btsocket_l2cap_raw_node = NULL; ng_btsocket_l2cap_raw_debug_level = NG_BTSOCKET_WARN_LEVEL; ng_btsocket_l2cap_raw_ioctl_timeout = 5; @@ -582,6 +578,8 @@ ng_btsocket_l2cap_raw_init(void) TASK_INIT(&ng_btsocket_l2cap_raw_rt_task, 0, ng_btsocket_l2cap_raw_rtclean, NULL); } /* ng_btsocket_l2cap_raw_init */ +SYSINIT(ng_btsocket_l2cap_raw_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, + ng_btsocket_l2cap_raw_init, NULL); /* * Abort connection on socket diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c b/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c index 5b7bbeb45407..d24e830becb1 100644 --- a/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c +++ b/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c @@ -328,14 +328,10 @@ ng_btsocket_rfcomm_check_fcs(u_int8_t *data, int type, u_int8_t fcs) * Initialize everything */ -void -ng_btsocket_rfcomm_init(void) +static void +ng_btsocket_rfcomm_init(void *arg __unused) { - /* Skip initialization of globals for non-default instances. */ - if (!IS_DEFAULT_VNET(curvnet)) - return; - ng_btsocket_rfcomm_debug_level = NG_BTSOCKET_WARN_LEVEL; ng_btsocket_rfcomm_timo = 60; @@ -353,6 +349,8 @@ ng_btsocket_rfcomm_init(void) mtx_init(&ng_btsocket_rfcomm_sockets_mtx, "btsocks_rfcomm_sockets_mtx", NULL, MTX_DEF); } /* ng_btsocket_rfcomm_init */ +SYSINIT(ng_btsocket_rfcomm_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, + ng_btsocket_rfcomm_init, NULL); /* * Abort connection on socket diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_sco.c b/sys/netgraph/bluetooth/socket/ng_btsocket_sco.c index 068b1890f27f..92898dad3245 100644 --- a/sys/netgraph/bluetooth/socket/ng_btsocket_sco.c +++ b/sys/netgraph/bluetooth/socket/ng_btsocket_sco.c @@ -1098,15 +1098,11 @@ ng_btsocket_sco_rtclean(void *context, int pending) * Initialize everything */ -void -ng_btsocket_sco_init(void) +static void +ng_btsocket_sco_init(void *arg __unused) { int error = 0; - /* Skip initialization of globals for non-default instances. */ - if (!IS_DEFAULT_VNET(curvnet)) - return; - ng_btsocket_sco_node = NULL; ng_btsocket_sco_debug_level = NG_BTSOCKET_WARN_LEVEL; @@ -1160,6 +1156,8 @@ ng_btsocket_sco_init(void) TASK_INIT(&ng_btsocket_sco_rt_task, 0, ng_btsocket_sco_rtclean, NULL); } /* ng_btsocket_sco_init */ +SYSINIT(ng_btsocket_sco_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, + ng_btsocket_sco_init, NULL); /* * Abort connection on socket diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 351c90699fc2..035051c6f5da 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -113,7 +113,6 @@ struct protosw inetsw[] = { .pr_domain = &inetdomain, .pr_protocol = IPPROTO_IP, .pr_flags = PR_CAPATTACH, - .pr_init = ip_init, .pr_slowtimo = ip_slowtimo, .pr_drain = ip_drain, .pr_usrreqs = &nousrreqs @@ -126,7 +125,6 @@ struct protosw inetsw[] = { .pr_input = udp_input, .pr_ctlinput = udp_ctlinput, .pr_ctloutput = udp_ctloutput, - .pr_init = udp_init, .pr_usrreqs = &udp_usrreqs }, { @@ -138,7 +136,6 @@ struct protosw inetsw[] = { .pr_input = tcp_input, .pr_ctlinput = tcp_ctlinput, .pr_ctloutput = tcp_ctloutput, - .pr_init = tcp_init, .pr_slowtimo = tcp_slowtimo, .pr_drain = tcp_drain, .pr_usrreqs = &tcp_usrreqs @@ -152,7 +149,6 @@ struct protosw inetsw[] = { .pr_input = sctp_input, .pr_ctlinput = sctp_ctlinput, .pr_ctloutput = sctp_ctloutput, - .pr_init = sctp_init, .pr_drain = sctp_drain, .pr_usrreqs = &sctp_usrreqs }, @@ -176,7 +172,6 @@ struct protosw inetsw[] = { .pr_input = udp_input, .pr_ctlinput = udplite_ctlinput, .pr_ctloutput = udp_ctloutput, - .pr_init = udplite_init, .pr_usrreqs = &udp_usrreqs }, { @@ -290,7 +285,6 @@ IPPROTOSPACER, .pr_flags = PR_ATOMIC|PR_ADDR, .pr_input = rip_input, .pr_ctloutput = rip_ctloutput, - .pr_init = rip_init, .pr_usrreqs = &rip_usrreqs }, }; diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index cd0034008dc2..8f972f49b604 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -143,7 +143,7 @@ div_inpcb_init(void *mem, int size, int flags) } static void -div_init(void) +div_init(void *arg __unused) { /* @@ -153,6 +153,7 @@ div_init(void) */ in_pcbinfo_init(&V_divcbinfo, "div", 1, 1, "divcb", div_inpcb_init); } +VNET_SYSINIT(div_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, div_init, NULL); static void div_destroy(void *unused __unused) @@ -160,8 +161,7 @@ div_destroy(void *unused __unused) in_pcbinfo_destroy(&V_divcbinfo); } -VNET_SYSUNINIT(divert, SI_SUB_PROTO_DOMAININIT, SI_ORDER_ANY, - div_destroy, NULL); +VNET_SYSUNINIT(divert, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, div_destroy, NULL); /* * IPPROTO_DIVERT is not in the real IP protocol number space; this @@ -775,7 +775,6 @@ struct protosw div_protosw = { .pr_protocol = IPPROTO_DIVERT, .pr_flags = PR_ATOMIC|PR_ADDR, .pr_input = div_input, - .pr_init = div_init, .pr_usrreqs = &div_usrreqs }; diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index c933a8044e06..8fd26e4ca861 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -301,12 +301,10 @@ SYSCTL_PROC(_net_inet_ip, IPCTL_INTRDQDROPS, intr_direct_queue_drops, * IP initialization: fill in IP protocol switch table. * All protocols not implemented in kernel go to raw IP protocol handler. */ -void -ip_init(void) +static void +ip_vnet_init(void *arg __unused) { struct pfil_head_args args; - struct protosw *pr; - int i; CK_STAILQ_INIT(&V_in_ifaddrhead); V_in_ifaddrhashtbl = hashinit(INADDR_NHASH, M_IFADDR, &V_in_ifaddrhmask); @@ -332,23 +330,27 @@ ip_init(void) printf("%s: WARNING: unable to register output helper hook\n", __func__); - /* Skip initialization of globals for non-default instances. */ #ifdef VIMAGE - if (!IS_DEFAULT_VNET(curvnet)) { - netisr_register_vnet(&ip_nh); + netisr_register_vnet(&ip_nh); #ifdef RSS - netisr_register_vnet(&ip_direct_nh); + netisr_register_vnet(&ip_direct_nh); #endif - return; - } #endif +} +VNET_SYSINIT(ip_vnet_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, + ip_vnet_init, NULL); + + +static void +ip_init(const void *unused __unused) +{ + struct protosw *pr; pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); - if (pr == NULL) - panic("ip_init: PF_INET not found"); + KASSERT(pr, ("%s: PF_INET not found", __func__)); /* Initialize the entire ip_protox[] array to IPPROTO_RAW. */ - for (i = 0; i < IPPROTO_MAX; i++) + for (int i = 0; i < IPPROTO_MAX; i++) ip_protox[i] = pr - inetsw; /* * Cycle through IP protocols and put them into the appropriate place @@ -368,6 +370,7 @@ ip_init(void) netisr_register(&ip_direct_nh); #endif } +SYSINIT(ip_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, ip_init, NULL); #ifdef VIMAGE static void diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index d5c68442a2b9..4eaaef5c6991 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -219,7 +219,6 @@ void ip_drain(void); int ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu, u_long if_hwassist_flags); void ip_forward(struct mbuf *m, int srcrt); -void ip_init(void); extern int (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *, struct ip_moptions *); @@ -236,7 +235,6 @@ void ip_slowtimo(void); void ip_fillid(struct ip *); int rip_ctloutput(struct socket *, struct sockopt *); void rip_ctlinput(int, struct sockaddr *, void *); -void rip_init(void); int rip_input(struct mbuf **, int *, int); int rip_output(struct mbuf *, struct socket *, ...); int ipip_input(struct mbuf **, int *, int); diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index de4e6e851c32..b7d338306b49 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -205,8 +205,8 @@ rip_inpcb_init(void *mem, int size, int flags) return (0); } -void -rip_init(void) +static void +rip_init(void *arg __unused) { in_pcbinfo_init(&V_ripcbinfo, "rip", INP_PCBHASH_RAW_SIZE, 1, "ripcb", @@ -214,6 +214,7 @@ rip_init(void) EVENTHANDLER_REGISTER(maxsockets_change, rip_zone_change, NULL, EVENTHANDLER_PRI_ANY); } +VNET_SYSINIT(rip_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, rip_init, NULL); #ifdef VIMAGE static void diff --git a/sys/netinet/sctp_module.c b/sys/netinet/sctp_module.c index 50b09eb6f930..70a9daeffc2a 100644 --- a/sys/netinet/sctp_module.c +++ b/sys/netinet/sctp_module.c @@ -91,7 +91,6 @@ struct protosw sctp6_stream_protosw = { .pr_input = sctp6_input, .pr_ctlinput = sctp6_ctlinput, .pr_ctloutput = sctp_ctloutput, - .pr_init = sctp_init, .pr_drain = sctp_drain, .pr_usrreqs = &sctp6_usrreqs, }; @@ -105,7 +104,6 @@ struct protosw sctp6_seqpacket_protosw = { .pr_ctlinput = sctp6_ctlinput, .pr_ctloutput = sctp_ctloutput, #ifndef INET /* Do not call initialization and drain routines twice. */ - .pr_init = sctp_init, .pr_drain = sctp_drain, #endif .pr_usrreqs = &sctp6_usrreqs, diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c index e30d02dc9de1..9ac57155c3bb 100644 --- a/sys/netinet/sctp_usrreq.c +++ b/sys/netinet/sctp_usrreq.c @@ -58,8 +58,8 @@ __FBSDID("$FreeBSD$"); extern const struct sctp_cc_functions sctp_cc_functions[]; extern const struct sctp_ss_functions sctp_ss_functions[]; -void -sctp_init(void) +static void +sctp_init(void *arg __unused) { u_long sb_max_adj; @@ -91,6 +91,7 @@ sctp_init(void) SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg, sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST); } +VNET_SYSINIT(sctp_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, sctp_init, NULL); #ifdef VIMAGE static void diff --git a/sys/netinet/sctp_var.h b/sys/netinet/sctp_var.h index a18dbb5e66e2..b45c4ac410f9 100644 --- a/sys/netinet/sctp_var.h +++ b/sys/netinet/sctp_var.h @@ -330,7 +330,6 @@ int sctp_input(struct mbuf **, int *, int); #endif void sctp_pathmtu_adjustment(struct sctp_tcb *, uint32_t, bool); void sctp_drain(void); -void sctp_init(void); void sctp_notify(struct sctp_inpcb *, struct sctp_tcb *, struct sctp_nets *, uint8_t, uint8_t, uint16_t, uint32_t); diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 041e639a447b..3a02988e5b6d 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1422,13 +1422,9 @@ deregister_tcp_functions(struct tcp_function_block *blk, bool quiesce, return (0); } -void -tcp_init(void) +static void +tcp_vnet_init(void *arg __unused) { - const char *tcbhash_tuneable; - int hashsize; - - tcbhash_tuneable = "net.inet.tcp.tcbhashsize"; #ifdef TCP_HHOOK if (hhook_head_register(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN, @@ -1443,46 +1439,7 @@ tcp_init(void) printf("%s: WARNING: unable to initialise TCP stats\n", __func__); #endif - hashsize = TCBHASHSIZE; - TUNABLE_INT_FETCH(tcbhash_tuneable, &hashsize); - if (hashsize == 0) { - /* - * Auto tune the hash size based on maxsockets. - * A perfect hash would have a 1:1 mapping - * (hashsize = maxsockets) however it's been - * suggested that O(2) average is better. - */ - hashsize = maketcp_hashsize(maxsockets / 4); - /* - * Our historical default is 512, - * do not autotune lower than this. - */ - if (hashsize < 512) - hashsize = 512; - if (bootverbose && IS_DEFAULT_VNET(curvnet)) - printf("%s: %s auto tuned to %d\n", __func__, - tcbhash_tuneable, hashsize); - } - /* - * We require a hashsize to be a power of two. - * Previously if it was not a power of two we would just reset it - * back to 512, which could be a nasty surprise if you did not notice - * the error message. - * Instead what we do is clip it to the closest power of two lower - * than the specified hash value. - */ - if (!powerof2(hashsize)) { - int oldhashsize = hashsize; - - hashsize = maketcp_hashsize(hashsize); - /* prevent absurdly low value */ - if (hashsize < 16) - hashsize = 16; - printf("%s: WARNING: TCB hash size not a power of 2, " - "clipped from %d to %d.\n", __func__, oldhashsize, - hashsize); - } - in_pcbinfo_init(&V_tcbinfo, "tcp", hashsize, hashsize, + in_pcbinfo_init(&V_tcbinfo, "tcp", tcp_tcbhashsize, tcp_tcbhashsize, "tcp_inpcb", tcp_inpcb_init); /* @@ -1507,10 +1464,15 @@ tcp_init(void) VNET_PCPUSTAT_ALLOC(tcpstat, M_WAITOK); V_tcp_msl = TCPTV_MSL; +} +VNET_SYSINIT(tcp_vnet_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, + tcp_vnet_init, NULL); - /* Skip initialization of globals for non-default instances. */ - if (!IS_DEFAULT_VNET(curvnet)) - return; +static void +tcp_init(void *arg __unused) +{ + const char *tcbhash_tuneable; + int hashsize; tcp_reass_global_init(); @@ -1530,7 +1492,6 @@ tcp_init(void) tcp_persmax = TCPTV_PERSMAX; tcp_rexmit_slop = TCPTV_CPU_VAR; tcp_finwait2_timeout = TCPTV_FINWAIT2_TIMEOUT; - tcp_tcbhashsize = hashsize; /* Setup the tcp function block list */ TAILQ_INIT(&t_functions); @@ -1580,7 +1541,50 @@ tcp_init(void) #ifdef TCPPCAP tcp_pcap_init(); #endif + + hashsize = TCBHASHSIZE; + tcbhash_tuneable = "net.inet.tcp.tcbhashsize"; + TUNABLE_INT_FETCH(tcbhash_tuneable, &hashsize); + if (hashsize == 0) { + /* + * Auto tune the hash size based on maxsockets. + * A perfect hash would have a 1:1 mapping + * (hashsize = maxsockets) however it's been + * suggested that O(2) average is better. + */ + hashsize = maketcp_hashsize(maxsockets / 4); + /* + * Our historical default is 512, + * do not autotune lower than this. + */ + if (hashsize < 512) + hashsize = 512; + if (bootverbose) + printf("%s: %s auto tuned to %d\n", __func__, + tcbhash_tuneable, hashsize); + } + /* + * We require a hashsize to be a power of two. + * Previously if it was not a power of two we would just reset it + * back to 512, which could be a nasty surprise if you did not notice + * the error message. + * Instead what we do is clip it to the closest power of two lower + * than the specified hash value. + */ + if (!powerof2(hashsize)) { + int oldhashsize = hashsize; + + hashsize = maketcp_hashsize(hashsize); + /* prevent absurdly low value */ + if (hashsize < 16) + hashsize = 16; + printf("%s: WARNING: TCB hash size not a power of 2, " + "clipped from %d to %d.\n", __func__, oldhashsize, + hashsize); + } + tcp_tcbhashsize = hashsize; } +SYSINIT(tcp_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, tcp_init, NULL); #ifdef VIMAGE static void diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 7792e2162852..e9d021fb4684 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1076,7 +1076,6 @@ void tcp_ctlinput(int, struct sockaddr *, void *); int tcp_ctloutput(struct socket *, struct sockopt *); void tcp_ctlinput_viaudp(int, struct sockaddr *, void *, void *); void tcp_drain(void); -void tcp_init(void); void tcp_fini(void *); char *tcp_log_addrs(struct in_conninfo *, struct tcphdr *, void *, const void *); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 28a1b3e89a41..582486ffbc92 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -198,8 +198,8 @@ udplite_inpcb_init(void *mem, int size, int flags) return (0); } -void -udp_init(void) +static void +udp_init(void *arg __unused) { /* @@ -217,15 +217,12 @@ udp_init(void) uma_zone_set_warning(V_udpcb_zone, "kern.ipc.maxsockets limit reached"); EVENTHANDLER_REGISTER(maxsockets_change, udp_zone_change, NULL, EVENTHANDLER_PRI_ANY); -} - -void -udplite_init(void) -{ + /* Additional pcbinfo for UDP-Lite */ in_pcbinfo_init(&V_ulitecbinfo, "udplite", UDBHASHSIZE, UDBHASHSIZE, "udplite_inpcb", udplite_inpcb_init); } +VNET_SYSINIT(udp_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, udp_init, NULL); /* * Kernel module interface for updating udpstat. The argument is an index diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 7e6260d20375..cd9c4fd47e4f 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -170,8 +170,6 @@ void udp_discardcb(struct udpcb *); void udp_ctlinput(int, struct sockaddr *, void *); void udplite_ctlinput(int, struct sockaddr *, void *); int udp_ctloutput(struct socket *, struct sockopt *); -void udp_init(void); -void udplite_init(void); int udp_input(struct mbuf **, int *, int); void udplite_input(struct mbuf *, int); struct inpcb *udp_notify(struct inpcb *inp, int errno); diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 909564b8c7e5..44eb0fa4ee62 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -146,7 +146,6 @@ struct protosw inet6sw[] = { .pr_domain = &inet6domain, .pr_protocol = IPPROTO_IPV6, .pr_flags = PR_CAPATTACH, - .pr_init = ip6_init, .pr_slowtimo = frag6_slowtimo, .pr_drain = frag6_drain, .pr_usrreqs = &nousrreqs, @@ -159,9 +158,6 @@ struct protosw inet6sw[] = { .pr_input = udp6_input, .pr_ctlinput = udp6_ctlinput, .pr_ctloutput = ip6_ctloutput, -#ifndef INET /* Do not call initialization twice. */ - .pr_init = udp_init, -#endif .pr_usrreqs = &udp6_usrreqs, }, { @@ -174,7 +170,6 @@ struct protosw inet6sw[] = { .pr_ctlinput = tcp6_ctlinput, .pr_ctloutput = tcp_ctloutput, #ifndef INET /* don't call initialization, timeout, and drain routines twice */ - .pr_init = tcp_init, .pr_slowtimo = tcp_slowtimo, .pr_drain = tcp_drain, #endif @@ -191,7 +186,6 @@ struct protosw inet6sw[] = { .pr_ctloutput = sctp_ctloutput, #ifndef INET /* Do not call initialization and drain routines twice. */ .pr_drain = sctp_drain, - .pr_init = sctp_init, #endif .pr_usrreqs = &sctp6_usrreqs }, @@ -215,9 +209,6 @@ struct protosw inet6sw[] = { .pr_input = udp6_input, *** 131 LINES SKIPPED ***