diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-07-17 19:57:33 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-07-17 19:57:33 +0000 |
commit | add232635541fa98afa0c46b0022a3303a0cc3d4 (patch) | |
tree | eb984c1ac8ba341ddb54c1b1b2b82c21407ea13b /sys/net/rtsock.c | |
parent | 249dc6878617b9aa800a6c7b9c5feb02da7ade22 (diff) |
Convert struct rtpcb malloc(9) to pool_get(9). PCB for routing
socket is only used in process context, so pass PR_WAITOK to
pool_init(9). The possible sleep in pool_put(9) should not hurt
as route_detach() is only called by soclose(9). As both pr_attach()
and pr_detach() are always called with kernel lock, PR_RWLOCK is
not needed.
OK mpi@
Diffstat (limited to 'sys/net/rtsock.c')
-rw-r--r-- | sys/net/rtsock.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index bd43a731387..0d957bb0c9b 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.288 2019/06/21 17:11:42 mpi Exp $ */ +/* $OpenBSD: rtsock.c,v 1.289 2019/07/17 19:57:32 bluhm Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -69,6 +69,7 @@ #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/domain.h> +#include <sys/pool.h> #include <sys/protosw.h> #include <sys/srp.h> @@ -158,6 +159,7 @@ struct rtptable { unsigned int rtp_count; }; +struct pool rtpcb_pool; struct rtptable rtptable; /* @@ -177,6 +179,8 @@ route_prinit(void) srpl_rc_init(&rtptable.rtp_rc, rcb_ref, rcb_unref, NULL); rw_init(&rtptable.rtp_lk, "rtsock"); SRPL_INIT(&rtptable.rtp_list); + pool_init(&rtpcb_pool, sizeof(struct rtpcb), 0, + IPL_NONE, PR_WAITOK, "rtpcb", NULL); } void @@ -294,7 +298,7 @@ route_attach(struct socket *so, int proto) * code does not care about the additional fields * and works directly on the raw socket. */ - rop = malloc(sizeof(struct rtpcb), M_PCB, M_WAITOK|M_ZERO); + rop = pool_get(&rtpcb_pool, PR_WAITOK|PR_ZERO); so->so_pcb = rop; /* Init the timeout structure */ timeout_set(&rop->rop_timeout, rtm_senddesync_timer, so); @@ -305,7 +309,7 @@ route_attach(struct socket *so, int proto) else error = soreserve(so, ROUTESNDQ, ROUTERCVQ); if (error) { - free(rop, M_PCB, sizeof(struct rtpcb)); + pool_put(&rtpcb_pool, rop); return (error); } @@ -350,7 +354,7 @@ route_detach(struct socket *so) so->so_pcb = NULL; KASSERT((so->so_state & SS_NOFDREF) == 0); - free(rop, M_PCB, sizeof(struct rtpcb)); + pool_put(&rtpcb_pool, rop); return (0); } |