diff options
author | mvs <mvs@cvs.openbsd.org> | 2021-05-02 14:22:06 +0000 |
---|---|---|
committer | mvs <mvs@cvs.openbsd.org> | 2021-05-02 14:22:06 +0000 |
commit | b080a695753450a848661a34d7c969d8ce50ee95 (patch) | |
tree | d72f167c617904a6d46a186a5edbc10cf84a08c1 /sys | |
parent | 95a251fcd47b8c5fc1307832db084d23baa71d56 (diff) |
Do soreserve() before `kp' allocation. This simplifies error path. The
same was done for route_attach().
Also do soisconnected() after `kp' is fully initialized. This chair
movement affects nothing for PF_KEY sockets but makes code more
consistent.
ok bluhm@ mpi@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/pfkeyv2.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index a757bf04d8e..e03c899eaa7 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.208 2020/12/14 20:20:06 tobhe Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.209 2021/05/02 14:22:05 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -269,24 +269,20 @@ pfkeyv2_attach(struct socket *so, int proto) if ((so->so_state & SS_PRIV) == 0) return EACCES; - 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) { - pool_put(&pkpcb_pool, kp); + if (error) return (error); - } + kp = pool_get(&pkpcb_pool, PR_WAITOK|PR_ZERO); + so->so_pcb = kp; + refcnt_init(&kp->kcb_refcnt); kp->kcb_socket = so; + kp->kcb_pid = curproc->p_p->ps_pid; + kp->kcb_rdomain = rtable_l2(curproc->p_p->ps_rtableid); so->so_options |= SO_USELOOPBACK; soisconnected(so); - kp->kcb_pid = curproc->p_p->ps_pid; - kp->kcb_rdomain = rtable_l2(curproc->p_p->ps_rtableid); - rw_enter(&pkptable.pkp_lk, RW_WRITE); SRPL_INSERT_HEAD_LOCKED(&pkptable.pkp_rc, &pkptable.pkp_list, kp, kcb_list); rw_exit(&pkptable.pkp_lk); |