diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-07-17 18:52:47 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-07-17 18:52:47 +0000 |
commit | 2b5caba4f1317bfab009f283e381f68e92512bf1 (patch) | |
tree | bc1462562503a2b730a66cddbe40d48c0d1831fd | |
parent | 792217b888fa083f6fca5413f3c07688a8ad0f48 (diff) |
Convert struct pkpcb malloc(9) to pool_get(9). PCB for pfkey 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 pfkeyv2_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@
-rw-r--r-- | sys/net/pfkeyv2.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index a976c5b79d1..31bd450fab2 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.197 2019/02/04 21:40:52 bluhm Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.198 2019/07/17 18:52:46 bluhm Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -129,6 +129,7 @@ extern struct pool ipsec_policy_pool; extern struct radix_node_head **spd_tables; +struct pool pkpcb_pool; #define PFKEY_MSG_MAXSZ 4096 const struct sockaddr pfkey_addr = { 2, PF_KEY, }; struct domain pfkeydomain; @@ -251,6 +252,8 @@ pfkey_init(void) srpl_rc_init(&pkptable.pkp_rc, keycb_ref, keycb_unref, NULL); rw_init(&pkptable.pkp_lk, "pfkey"); SRPL_INIT(&pkptable.pkp_list); + pool_init(&pkpcb_pool, sizeof(struct pkpcb), 0, + IPL_NONE, PR_WAITOK, "pkpcb", NULL); } @@ -266,13 +269,13 @@ pfkeyv2_attach(struct socket *so, int proto) if ((so->so_state & SS_PRIV) == 0) return EACCES; - kp = malloc(sizeof(struct pkpcb), M_PCB, M_WAITOK | M_ZERO); + kp = pool_get(&pkpcb_pool, PR_WAITOK|PR_ZERO); so->so_pcb = kp; refcnt_init(&kp->kcb_refcnt); error = soreserve(so, PFKEYSNDQ, PFKEYRCVQ); if (error) { - free(kp, M_PCB, sizeof(struct pkpcb)); + pool_put(&pkpcb_pool, kp); return (error); } @@ -326,7 +329,7 @@ pfkeyv2_detach(struct socket *so) so->so_pcb = NULL; KASSERT((so->so_state & SS_NOFDREF) == 0); - free(kp, M_PCB, sizeof(struct pkpcb)); + pool_put(&pkpcb_pool, kp); return (0); } |