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
This commit is contained in:
Gleb Smirnoff 2022-01-03 10:15:21 -08:00
parent 321e586e46
commit 89128ff3e4
35 changed files with 126 additions and 190 deletions

View File

@ -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 */

View File

@ -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:

View File

@ -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 *);

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -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
}
};

View File

@ -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 *);

View File

@ -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 **);

View File

@ -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 **);

View File

@ -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 **);

View File

@ -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,
},
};

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
},
};

View File

@ -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
};

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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 *);

View File

@ -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

View File

@ -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);

View File

@ -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,
.pr_ctlinput = udplite6_ctlinput,
.pr_ctloutput = udp_ctloutput,
#ifndef INET /* Do not call initialization twice. */
.pr_init = udplite_init,
#endif
.pr_usrreqs = &udp6_usrreqs,
},
{
@ -229,9 +220,6 @@ struct protosw inet6sw[] = {
.pr_output = rip6_output,
.pr_ctlinput = rip6_ctlinput,
.pr_ctloutput = rip6_ctloutput,
#ifndef INET /* Do not call initialization twice. */
.pr_init = rip_init,
#endif
.pr_usrreqs = &rip6_usrreqs
},
{

View File

@ -216,12 +216,10 @@ static int ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *);
* IP6 initialization: fill in IP6 protocol switch table.
* All protocols not implemented in kernel go to raw IP6 protocol handler.
*/
void
ip6_init(void)
static void
ip6_vnet_init(void *arg __unused)
{
struct pfil_head_args args;
struct protosw *pr;
int i;
TUNABLE_INT_FETCH("net.inet6.ip6.auto_linklocal",
&V_ip6_auto_linklocal);
@ -259,21 +257,25 @@ ip6_init(void)
/* Skip global initialization stuff for non-default instances. */
#ifdef VIMAGE
if (!IS_DEFAULT_VNET(curvnet)) {
netisr_register_vnet(&ip6_nh);
netisr_register_vnet(&ip6_nh);
#ifdef RSS
netisr_register_vnet(&ip6_direct_nh);
netisr_register_vnet(&ip6_direct_nh);
#endif
return;
}
#endif
}
VNET_SYSINIT(ip6_vnet_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH,
ip6_vnet_init, NULL);
static void
ip6_init(void *arg __unused)
{
struct protosw *pr;
pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
if (pr == NULL)
panic("ip6_init");
KASSERT(pr, ("%s: PF_INET6 not found", __func__));
/* Initialize the entire ip6_protox[] array to IPPROTO_RAW. */
for (i = 0; i < IPPROTO_MAX; i++)
for (int i = 0; i < IPPROTO_MAX; i++)
ip6_protox[i] = pr - inet6sw;
/*
* Cycle through IP protocols and put them into the appropriate place
@ -293,6 +295,7 @@ ip6_init(void)
netisr_register(&ip6_direct_nh);
#endif
}
SYSINIT(ip6_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, ip6_init, NULL);
/*
* The protocol to be inserted into ip6_protox[] must be already registered

View File

@ -347,7 +347,6 @@ struct inpcb;
int icmp6_ctloutput(struct socket *, struct sockopt *sopt);
struct in6_ifaddr;
void ip6_init(void);
int ip6proto_register(short);
int ip6proto_unregister(short);

View File

@ -448,7 +448,6 @@ struct protosw keysw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_output = key_output,
.pr_ctlinput = raw_ctlinput,
.pr_init = raw_init,
.pr_usrreqs = &key_usrreqs
}
};

View File

@ -52,7 +52,6 @@ struct sockopt;
* Each protocol has a handle initializing one of these structures,
* which is used for protocol-protocol and system-protocol communication.
*
* A protocol is called through the pr_init entry before any other.
* Thereafter it is called every 200ms through the pr_fasttimo entry and
* every 500ms through the pr_slowtimo for timer based actions.
* The system will call the pr_drain entry if it is low on space and
@ -73,7 +72,6 @@ typedef int pr_input_t (struct mbuf **, int*, int);
typedef int pr_output_t (struct mbuf *, struct socket *, ...);
typedef void pr_ctlinput_t (int, struct sockaddr *, void *);
typedef int pr_ctloutput_t (struct socket *, struct sockopt *);
typedef void pr_init_t (void);
typedef void pr_fasttimo_t (void);
typedef void pr_slowtimo_t (void);
typedef void pr_drain_t (void);
@ -89,7 +87,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 */