for the lock operation and to pass a value to the unlock operation.
sofree() still needs an extra flag to know if sounlock() should be called
or not. But sofree() is called less often and mostly without keeping the lock.
OK mpi@ mvs@
-/* $OpenBSD: sys_socket.c,v 1.49 2022/02/25 23:51:03 guenther Exp $ */
+/* $OpenBSD: sys_socket.c,v 1.50 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */
/*
soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
{
struct socket *so = (struct socket *)fp->f_data;
- int s, error = 0;
+ int error = 0;
switch (cmd) {
break;
case FIOASYNC:
- s = solock(so);
+ solock(so);
if (*(int *)data) {
so->so_rcv.sb_flags |= SB_ASYNC;
so->so_snd.sb_flags |= SB_ASYNC;
so->so_rcv.sb_flags &= ~SB_ASYNC;
so->so_snd.sb_flags &= ~SB_ASYNC;
}
- sounlock(so, s);
+ sounlock(so);
break;
case FIONREAD:
{
struct socket *so = fp->f_data;
int revents = 0;
- int s;
- s = solock(so);
+ solock(so);
if (events & (POLLIN | POLLRDNORM)) {
if (soreadable(so))
revents |= events & (POLLIN | POLLRDNORM);
so->so_snd.sb_flags |= SB_SEL;
}
}
- sounlock(so, s);
+ sounlock(so);
return (revents);
}
soo_stat(struct file *fp, struct stat *ub, struct proc *p)
{
struct socket *so = fp->f_data;
- int s;
memset(ub, 0, sizeof (*ub));
ub->st_mode = S_IFSOCK;
- s = solock(so);
+ solock(so);
if ((so->so_state & SS_CANTRCVMORE) == 0 || so->so_rcv.sb_cc != 0)
ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
if ((so->so_state & SS_CANTSENDMORE) == 0)
ub->st_gid = so->so_egid;
(void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
(struct mbuf *)ub, NULL, NULL, p));
- sounlock(so, s);
+ sounlock(so);
return (0);
}
-/* $OpenBSD: uipc_socket.c,v 1.277 2022/05/09 14:49:55 visa Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.278 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
struct proc *p = curproc; /* XXX */
const struct protosw *prp;
struct socket *so;
- int error, s;
+ int error;
if (proto)
prp = pffindproto(dom, proto, type);
so->so_snd.sb_timeo_nsecs = INFSLP;
so->so_rcv.sb_timeo_nsecs = INFSLP;
- s = solock(so);
+ solock(so);
error = (*prp->pr_attach)(so, proto);
if (error) {
so->so_state |= SS_NOFDREF;
/* sofree() calls sounlock(). */
- sofree(so, s);
+ sofree(so, 0);
return (error);
}
- sounlock(so, s);
+ sounlock(so);
*aso = so;
return (0);
}
#define SOSP_FREEING_READ 1
#define SOSP_FREEING_WRITE 2
void
-sofree(struct socket *so, int s)
+sofree(struct socket *so, int keep_lock)
{
soassertlocked(so);
if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) {
- sounlock(so, s);
+ if (!keep_lock)
+ sounlock(so);
return;
}
if (so->so_head) {
* indicated that the listening socket was ready.
*/
if (!soqremque(so, 0)) {
- sounlock(so, s);
+ if (!keep_lock)
+ sounlock(so);
return;
}
}
#endif /* SOCKET_SPLICE */
sbrelease(so, &so->so_snd);
sorflush(so);
- sounlock(so, s);
+ if (!keep_lock)
+ sounlock(so);
#ifdef SOCKET_SPLICE
if (so->so_sp) {
/* Reuse splice idle, sounsplice() has been called before. */
soclose(struct socket *so, int flags)
{
struct socket *so2;
- int s, error = 0;
+ int error = 0;
- s = solock(so);
+ solock(so);
/* Revoke async IO early. There is a final revocation in sofree(). */
sigio_free(&so->so_sigio);
if (so->so_state & SS_ISCONNECTED) {
panic("soclose NOFDREF: so %p, so_type %d", so, so->so_type);
so->so_state |= SS_NOFDREF;
/* sofree() calls sounlock(). */
- sofree(so, s);
+ sofree(so, 0);
return (error);
}
int
soconnect2(struct socket *so1, struct socket *so2)
{
- int s, error;
+ int error;
- s = solock(so1);
+ solock(so1);
error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, NULL,
(struct mbuf *)so2, NULL, curproc);
- sounlock(so1, s);
+ sounlock(so1);
return (error);
}
{
long space, clen = 0;
size_t resid;
- int error, s;
+ int error;
int atomic = sosendallatonce(so) || top;
if (uio)
#define snderr(errno) { error = errno; goto release; }
- s = solock(so);
+ solock(so);
restart:
if ((error = sblock(so, &so->so_snd, SBLOCKWAIT(flags))) != 0)
goto out;
if (flags & MSG_EOR)
top->m_flags |= M_EOR;
} else {
- sounlock(so, s);
+ sounlock(so);
error = m_getuio(&top, atomic, space, uio);
- s = solock(so);
+ solock(so);
if (error)
goto release;
space -= top->m_pkthdr.len;
so->so_state &= ~SS_ISSENDING;
sbunlock(so, &so->so_snd);
out:
- sounlock(so, s);
+ sounlock(so);
m_freem(top);
m_freem(control);
return (error);
struct mbuf *m, **mp;
struct mbuf *cm;
u_long len, offset, moff;
- int flags, error, s, type, uio_error = 0;
+ int flags, error, type, uio_error = 0;
const struct protosw *pr = so->so_proto;
struct mbuf *nextrecord;
size_t resid, orig_resid = uio->uio_resid;
flags = 0;
if (flags & MSG_OOB) {
m = m_get(M_WAIT, MT_DATA);
- s = solock(so);
+ solock(so);
error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m,
(struct mbuf *)(long)(flags & MSG_PEEK), NULL, curproc);
- sounlock(so, s);
+ sounlock(so);
if (error)
goto bad;
do {
if (mp)
*mp = NULL;
- s = solock(so);
+ solock(so);
restart:
if ((error = sblock(so, &so->so_rcv, SBLOCKWAIT(flags))) != 0) {
- sounlock(so, s);
+ sounlock(so);
return (error);
}
sbunlock(so, &so->so_rcv);
error = sbwait(so, &so->so_rcv);
if (error) {
- sounlock(so, s);
+ sounlock(so);
return (error);
}
goto restart;
sbsync(&so->so_rcv, nextrecord);
if (controlp) {
if (pr->pr_domain->dom_externalize) {
- sounlock(so, s);
+ sounlock(so);
error =
(*pr->pr_domain->dom_externalize)
(cm, controllen, flags);
- s = solock(so);
+ solock(so);
}
*controlp = cm;
} else {
SBLASTRECORDCHK(&so->so_rcv, "soreceive uiomove");
SBLASTMBUFCHK(&so->so_rcv, "soreceive uiomove");
resid = uio->uio_resid;
- sounlock(so, s);
+ sounlock(so);
uio_error = uiomove(mtod(m, caddr_t) + moff, len, uio);
- s = solock(so);
+ solock(so);
if (uio_error)
uio->uio_resid = resid - len;
} else
error = sbwait(so, &so->so_rcv);
if (error) {
sbunlock(so, &so->so_rcv);
- sounlock(so, s);
+ sounlock(so);
return (0);
}
if ((m = so->so_rcv.sb_mb) != NULL)
*flagsp |= flags;
release:
sbunlock(so, &so->so_rcv);
- sounlock(so, s);
+ sounlock(so);
return (error);
}
soshutdown(struct socket *so, int how)
{
const struct protosw *pr = so->so_proto;
- int s, error = 0;
+ int error = 0;
- s = solock(so);
+ solock(so);
switch (how) {
case SHUT_RD:
sorflush(so);
error = EINVAL;
break;
}
- sounlock(so, s);
+ sounlock(so);
return (error);
}
* socket when sosplice() returns. The dance could be avoided by
* grabbing the socket lock inside this function.
*/
- sounlock(so, SL_LOCKED);
+ sounlock(so);
FRELE(fp, curproc);
solock(so);
return (error);
soidle(void *arg)
{
struct socket *so = arg;
- int s;
- s = solock(so);
+ solock(so);
if (so->so_rcv.sb_flags & SB_SPLICE) {
so->so_error = ETIMEDOUT;
sounsplice(so, so->so_sp->ssp_socket, 0);
}
- sounlock(so, s);
+ sounlock(so);
}
void
sotask(void *arg)
{
struct socket *so = arg;
- int s;
- s = solock(so);
+ solock(so);
if (so->so_rcv.sb_flags & SB_SPLICE) {
/*
* We may not sleep here as sofree() and unsplice() may be
*/
somove(so, M_DONTWAIT);
}
- sounlock(so, s);
+ sounlock(so);
/* Avoid user land starvation. */
yield();
{
struct socket *so = kn->kn_fp->f_data;
struct sockbuf *sb;
- int s;
- s = solock(so);
+ solock(so);
switch (kn->kn_filter) {
case EVFILT_READ:
if (so->so_options & SO_ACCEPTCONN)
sb = &so->so_rcv;
break;
default:
- sounlock(so, s);
+ sounlock(so);
return (EINVAL);
}
klist_insert_locked(&sb->sb_sel.si_note, kn);
- sounlock(so, s);
+ sounlock(so);
return (0);
}
filt_somodify(struct kevent *kev, struct knote *kn)
{
struct socket *so = kn->kn_fp->f_data;
- int rv, s;
+ int rv;
- s = solock(so);
+ solock(so);
rv = knote_modify(kev, kn);
- sounlock(so, s);
+ sounlock(so);
return (rv);
}
filt_soprocess(struct knote *kn, struct kevent *kev)
{
struct socket *so = kn->kn_fp->f_data;
- int rv, s;
+ int rv;
- s = solock(so);
+ solock(so);
rv = knote_process(kn, kev);
- sounlock(so, s);
+ sounlock(so);
return (rv);
}
{
struct socket *so = arg;
- return (solock(so));
+ solock(so);
+ return (1);
}
void
{
struct socket *so = arg;
- sounlock(so, ls);
+ sounlock(so);
}
const struct klistops socket_klistops = {
-/* $OpenBSD: uipc_socket2.c,v 1.122 2022/05/09 14:49:55 visa Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.123 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
sorwakeup(so);
}
-int
+void
solock(struct socket *so)
{
switch (so->so_proto->pr_domain->dom_family) {
rw_enter_write(&so->so_lock);
break;
}
-
- return (SL_LOCKED);
}
void
-sounlock(struct socket *so, int s)
+sounlock(struct socket *so)
{
- KASSERT(s == SL_LOCKED || s == SL_NOUNLOCK);
-
- if (s != SL_LOCKED)
- return;
-
switch (so->so_proto->pr_domain->dom_family) {
case PF_INET:
case PF_INET6:
-/* $OpenBSD: uipc_syscalls.c,v 1.194 2021/10/24 00:02:25 jsg Exp $ */
+/* $OpenBSD: uipc_syscalls.c,v 1.195 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */
/*
struct file *fp;
struct mbuf *nam;
struct socket *so;
- int s, error;
+ int error;
if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
if (KTRPOINT(p, KTR_STRUCT))
ktrsockaddr(p, mtod(nam, caddr_t), SCARG(uap, namelen));
#endif
- s = solock(so);
+ solock(so);
error = sobind(so, nam, p);
- sounlock(so, s);
+ sounlock(so);
m_freem(nam);
out:
FRELE(fp, p);
} */ *uap = v;
struct file *fp;
struct socket *so;
- int s, error;
+ int error;
if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
so = fp->f_data;
- s = solock(so);
+ solock(so);
error = solisten(so, SCARG(uap, backlog));
- sounlock(so, s);
+ sounlock(so);
FRELE(fp, p);
return (error);
}
struct file *fp, *headfp;
struct mbuf *nam;
socklen_t namelen;
- int error, s, tmpfd;
+ int error, tmpfd;
struct socket *head, *so;
int cloexec, nflag;
nam = m_get(M_WAIT, MT_SONAME);
head = headfp->f_data;
- s = solock(head);
+ solock(head);
if (isdnssocket(head) || (head->so_options & SO_ACCEPTCONN) == 0) {
error = EINVAL;
goto out;
fp->f_data = so;
error = soaccept(so, nam);
out:
- sounlock(head, s);
+ sounlock(head);
if (!error && name != NULL)
error = copyaddrout(p, nam, name, namelen, anamelen);
if (!error) {
struct file *fp;
struct socket *so;
struct mbuf *nam;
- int error, s, interrupted = 0;
+ int error, interrupted = 0;
if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
if (KTRPOINT(p, KTR_STRUCT))
ktrsockaddr(p, mtod(nam, caddr_t), SCARG(uap, namelen));
#endif
- s = solock(so);
+ solock(so);
if (isdnssocket(so)) {
error = dns_portcheck(p, so, mtod(nam, void *), nam->m_len);
if (error)
if (!interrupted)
so->so_state &= ~SS_ISCONNECTING;
unlock:
- sounlock(so, s);
+ sounlock(so);
m_freem(nam);
out:
FRELE(fp, p);
struct file *fp;
struct mbuf *m = NULL;
struct socket *so;
- int s, error;
+ int error;
if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
m->m_len = SCARG(uap, valsize);
}
so = fp->f_data;
- s = solock(so);
+ solock(so);
error = sosetopt(so, SCARG(uap, level), SCARG(uap, name), m);
- sounlock(so, s);
+ sounlock(so);
bad:
m_freem(m);
FRELE(fp, p);
struct mbuf *m = NULL;
socklen_t valsize;
struct socket *so;
- int s, error;
+ int error;
if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
valsize = 0;
m = m_get(M_WAIT, MT_SOOPTS);
so = fp->f_data;
- s = solock(so);
+ solock(so);
error = sogetopt(so, SCARG(uap, level), SCARG(uap, name), m);
- sounlock(so, s);
+ sounlock(so);
if (error == 0 && SCARG(uap, val) && valsize && m != NULL) {
if (valsize > m->m_len)
valsize = m->m_len;
struct socket *so;
struct mbuf *m = NULL;
socklen_t len;
- int error, s;
+ int error;
if ((error = getsock(p, SCARG(uap, fdes), &fp)) != 0)
return (error);
if (error)
goto bad;
m = m_getclr(M_WAIT, MT_SONAME);
- s = solock(so);
+ solock(so);
error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, NULL, m, NULL, p);
- sounlock(so, s);
+ sounlock(so);
if (error)
goto bad;
error = copyaddrout(p, m, SCARG(uap, asa), len, SCARG(uap, alen));
struct socket *so;
struct mbuf *m = NULL;
socklen_t len;
- int error, s;
+ int error;
if ((error = getsock(p, SCARG(uap, fdes), &fp)) != 0)
return (error);
if (error)
goto bad;
m = m_getclr(M_WAIT, MT_SONAME);
- s = solock(so);
+ solock(so);
error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, NULL, m, NULL, p);
- sounlock(so, s);
+ sounlock(so);
if (error)
goto bad;
error = copyaddrout(p, m, SCARG(uap, asa), len, SCARG(uap, alen));
-/* $OpenBSD: uipc_usrreq.c,v 1.164 2022/04/11 18:18:17 mvs Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.165 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
case PRU_SEND:
if (control) {
- sounlock(so, SL_LOCKED);
+ sounlock(so);
error = unp_internalize(control, p);
solock(so);
if (error)
* uipc_usrreq() releasing it here would lead to a
* double unlock.
*/
- sofree(so, SL_NOUNLOCK);
+ sofree(so, 1);
break;
case PRU_SENSE: {
* listening socket protected by vnode(9) lock. The peer socket
* has 'UNP_CONNECTING' flag set.
*/
- sounlock(so, SL_LOCKED);
+ sounlock(so);
rw_enter_write(&unp_gc_lock);
LIST_INSERT_HEAD(&unp_head, unp, unp_link);
rw_exit_write(&unp_gc_lock);
* Enforce `unp_gc_lock' -> `solock()' lock order.
* Enforce `i_lock' -> `unp_lock' lock order.
*/
- sounlock(so, SL_LOCKED);
+ sounlock(so);
rw_enter_write(&unp_gc_lock);
LIST_REMOVE(unp, unp_link);
* because the file descriptor reference is still held.
*/
- sounlock(unp->unp_socket, SL_LOCKED);
+ sounlock(unp->unp_socket);
nam2 = m_getclr(M_WAITOK, MT_SONAME);
nam2->m_len = sizeof(struct sockaddr_un);
* because the file descriptor reference is still held.
*/
- sounlock(so, SL_LOCKED);
+ sounlock(so);
KERNEL_LOCK();
error = namei(&nd);
}
error = unp_connect2(so, so2);
put_locked:
- sounlock(so, SL_LOCKED);
+ sounlock(so);
put:
vput(vp);
unlock:
so = unp->unp_socket;
solock(so);
unp_scan(so->so_rcv.sb_mb, unp_remove_gcrefs);
- sounlock(so, SL_LOCKED);
+ sounlock(so);
}
/*
so = unp->unp_socket;
solock(so);
unp_scan(so->so_rcv.sb_mb, unp_restore_gcrefs);
- sounlock(so, SL_LOCKED);
+ sounlock(so);
KASSERT(nunref > 0);
nunref--;
so = unp->unp_socket;
solock(so);
unp_scan(so->so_rcv.sb_mb, unp_discard);
- sounlock(so, SL_LOCKED);
+ sounlock(so);
}
}
}
-/* $OpenBSD: fifo_vnops.c,v 1.93 2022/02/16 13:19:33 visa Exp $ */
+/* $OpenBSD: fifo_vnops.c,v 1.94 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: fifo_vnops.c,v 1.18 1996/03/16 23:52:42 christos Exp $ */
/*
struct vnode *vp = ap->a_vp;
struct fifoinfo *fip;
struct socket *rso, *wso;
- int s, error;
+ int error;
if ((fip = vp->v_fifoinfo) == NULL) {
fip = malloc(sizeof(*fip), M_VNODE, M_WAITOK);
return (error);
}
fip->fi_readers = fip->fi_writers = 0;
- s = solock(wso);
+ solock(wso);
wso->so_state |= SS_CANTSENDMORE;
wso->so_snd.sb_lowat = PIPE_BUF;
} else {
rso = fip->fi_readsock;
wso = fip->fi_writesock;
- s = solock(wso);
+ solock(wso);
}
if (ap->a_mode & FREAD) {
fip->fi_readers++;
fip->fi_writers++;
if ((ap->a_mode & O_NONBLOCK) && fip->fi_readers == 0) {
error = ENXIO;
- sounlock(wso, s);
+ sounlock(wso);
goto bad;
}
if (fip->fi_writers == 1) {
wakeup(&fip->fi_readers);
}
}
- sounlock(wso, s);
+ sounlock(wso);
if ((ap->a_mode & O_NONBLOCK) == 0) {
if ((ap->a_mode & FREAD) && fip->fi_writers == 0) {
VOP_UNLOCK(vp);
struct socket *wso = ap->a_vp->v_fifoinfo->fi_writesock;
int events = 0;
int revents = 0;
- int s;
/*
* FIFOs don't support out-of-band or high priority data.
*/
- s = solock(rso);
+ solock(rso);
if (ap->a_fflag & FREAD)
events |= ap->a_events & (POLLIN | POLLRDNORM);
if (ap->a_fflag & FWRITE)
wso->so_snd.sb_flags |= SB_SEL;
}
}
- sounlock(rso, s);
+ sounlock(rso);
return (revents);
}
struct vop_close_args *ap = v;
struct vnode *vp = ap->a_vp;
struct fifoinfo *fip = vp->v_fifoinfo;
- int s, error1 = 0, error2 = 0;
+ int error1 = 0, error2 = 0;
if (fip == NULL)
return (0);
if (--fip->fi_readers == 0) {
struct socket *wso = fip->fi_writesock;
- s = solock(wso);
+ solock(wso);
socantsendmore(wso);
- sounlock(wso, s);
+ sounlock(wso);
}
}
if (ap->a_fflag & FWRITE) {
if (--fip->fi_writers == 0) {
struct socket *rso = fip->fi_readsock;
- s = solock(rso);
+ solock(rso);
/* SS_ISDISCONNECTED will result in POLLHUP */
rso->so_state |= SS_ISDISCONNECTED;
socantrcvmore(rso);
- sounlock(rso, s);
+ sounlock(rso);
}
}
if (fip->fi_readers == 0 && fip->fi_writers == 0) {
filt_fifomodify(struct kevent *kev, struct knote *kn)
{
struct socket *so = kn->kn_hook;
- int rv, s;
+ int rv;
- s = solock(so);
+ solock(so);
rv = knote_modify(kev, kn);
- sounlock(so, s);
+ sounlock(so);
return (rv);
}
filt_fifoprocess(struct knote *kn, struct kevent *kev)
{
struct socket *so = kn->kn_hook;
- int rv, s;
+ int rv;
- s = solock(so);
+ solock(so);
rv = knote_process(kn, kev);
- sounlock(so, s);
+ sounlock(so);
return (rv);
}
-/* $OpenBSD: if_pflow.c,v 1.93 2020/08/21 22:59:27 kn Exp $ */
+/* $OpenBSD: if_pflow.c,v 1.94 2022/06/06 14:45:41 claudio Exp $ */
/*
* Copyright (c) 2011 Florian Obser <florian@narrans.de>
return (error);
if (pflowvalidsockaddr(sc->sc_flowsrc, 1)) {
struct mbuf *m;
- int s;
MGET(m, M_WAIT, MT_SONAME);
m->m_len = sc->sc_flowsrc->sa_len;
memcpy(sa, sc->sc_flowsrc,
sc->sc_flowsrc->sa_len);
- s = solock(so);
+ solock(so);
error = sobind(so, m, p);
- sounlock(so, s);
+ sounlock(so);
m_freem(m);
if (error) {
soclose(so, MSG_DONTWAIT);
-/* $OpenBSD: if_vxlan.c,v 1.90 2022/02/26 04:46:34 dlg Exp $ */
+/* $OpenBSD: if_vxlan.c,v 1.91 2022/06/06 14:45:41 claudio Exp $ */
/*
* Copyright (c) 2021 David Gwynne <dlg@openbsd.org>
struct sockaddr_in6 *sin6;
#endif
int error;
- int s;
vt = vxlan_tep_get(sc, addr);
if (vt != NULL) {
if (error != 0)
goto free;
- s = solock(so);
+ solock(so);
sotoinpcb(so)->inp_upcall = vxlan_input;
sotoinpcb(so)->inp_upcall_arg = vt;
if (error != 0)
goto close;
- sounlock(so, s);
+ sounlock(so);
rw_assert_wrlock(&vxlan_lock);
TAILQ_INSERT_TAIL(&vxlan_teps, vt, vt_entry);
return (0);
close:
- sounlock(so, s);
+ sounlock(so);
soclose(so, MSG_DONTWAIT);
free:
free(vt, M_DEVBUF, sizeof(*vt));
-/* $OpenBSD: if_wg.c,v 1.24 2022/03/17 18:51:56 tb Exp $ */
+/* $OpenBSD: if_wg.c,v 1.25 2022/06/06 14:45:41 claudio Exp $ */
/*
* Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
struct sockaddr_in6 *sin6;
#endif
struct sockaddr_in *sin;
- int ret, s;
+ int ret;
m_inithdr(&mhostnam);
m_inithdr(&mrtable);
if ((ret = socreate(af, so, SOCK_DGRAM, 0)) != 0)
return ret;
- s = solock(*so);
+ solock(*so);
sotoinpcb(*so)->inp_upcall = wg_input;
sotoinpcb(*so)->inp_upcall_arg = upcall_arg;
*rtable = sotoinpcb(*so)->inp_rtableid;
}
}
- sounlock(*so, s);
+ sounlock(*so);
if (ret != 0)
wg_socket_close(so);
-/* $OpenBSD: pfkeyv2.c,v 1.233 2022/03/13 21:38:32 bluhm Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.234 2022/06/06 14:45:41 claudio Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
};
#define sotokeycb(so) ((struct pkpcb *)(so)->so_pcb)
#define keylock(kp) solock((kp)->kcb_socket)
-#define keyunlock(kp, s) sounlock((kp)->kcb_socket, s)
+#define keyunlock(kp) sounlock((kp)->kcb_socket)
struct dump_state {
kcb_list);
rw_exit(&pkptable.pkp_lk);
- sounlock(so, SL_LOCKED);
+ sounlock(so);
/* wait for all references to drop */
refcnt_finalize(&kp->kcb_refcnt, "pfkeyrefs");
solock(so);
* descriptor reference is still held.
*/
- sounlock(so, SL_LOCKED);
+ sounlock(so);
error = pfkeyv2_send(so, message, mbuf->m_pkthdr.len);
solock(so);
pfkeyv2_sendmessage(void **headers, int mode, struct socket *so,
u_int8_t satype, int count, u_int rdomain)
{
- int i, j, rval, s;
+ int i, j, rval;
void *p, *buffer = NULL;
struct mbuf *packet;
struct pkpcb *kp;
* Send message to the specified socket, plus all
* promiscuous listeners.
*/
- s = solock(so);
+ solock(so);
pfkey_sendup(sotokeycb(so), packet, 0);
- sounlock(so, s);
+ sounlock(so);
/*
* Promiscuous messages contain the original message
if (kp->kcb_socket == so || kp->kcb_rdomain != rdomain)
continue;
- s = keylock(kp);
+ keylock(kp);
if (kp->kcb_flags & PFKEYV2_SOCKETFLAGS_PROMISC)
pfkey_sendup(kp, packet, 1);
- keyunlock(kp, s);
+ keyunlock(kp);
}
SRPL_LEAVE(&sr);
m_freem(packet);
if (kp->kcb_rdomain != rdomain)
continue;
- s = keylock(kp);
+ keylock(kp);
if (kp->kcb_flags & PFKEYV2_SOCKETFLAGS_REGISTERED) {
if (!satype) {
/* Just send to everyone registered */
pfkey_sendup(kp, packet, 1);
}
}
- keyunlock(kp, s);
+ keyunlock(kp);
}
SRPL_LEAVE(&sr);
/* Free last/original copy of the packet */
if (kp->kcb_rdomain != rdomain)
continue;
- s = keylock(kp);
+ keylock(kp);
if ((kp->kcb_flags & PFKEYV2_SOCKETFLAGS_PROMISC) &&
!(kp->kcb_flags & PFKEYV2_SOCKETFLAGS_REGISTERED))
pfkey_sendup(kp, packet, 1);
- keyunlock(kp, s);
+ keyunlock(kp);
}
SRPL_LEAVE(&sr);
m_freem(packet);
if (kp->kcb_rdomain != rdomain)
continue;
- s = keylock(kp);
+ keylock(kp);
pfkey_sendup(kp, packet, 1);
- keyunlock(kp, s);
+ keyunlock(kp);
}
SRPL_LEAVE(&sr);
m_freem(packet);
struct srp_ref sr;
struct sadb_x_rdomain *srdomain;
u_int rdomain = 0;
- int promisc, s;
+ int promisc;
mtx_enter(&pfkeyv2_mtx);
promisc = npromisc;
if (bkp->kcb_rdomain != kp->kcb_rdomain)
continue;
- s = keylock(bkp);
+ keylock(bkp);
if (bkp->kcb_flags & PFKEYV2_SOCKETFLAGS_PROMISC)
pfkey_sendup(bkp, packet, 1);
- keyunlock(bkp, s);
+ keyunlock(bkp);
}
SRPL_LEAVE(&sr);
break;
case SADB_REGISTER:
- s = keylock(kp);
+ keylock(kp);
if (!(kp->kcb_flags & PFKEYV2_SOCKETFLAGS_REGISTERED)) {
kp->kcb_flags |= PFKEYV2_SOCKETFLAGS_REGISTERED;
mtx_enter(&pfkeyv2_mtx);
nregistered++;
mtx_leave(&pfkeyv2_mtx);
}
- keyunlock(kp, s);
+ keyunlock(kp);
freeme_sz = sizeof(struct sadb_supported) + sizeof(ealgs);
if (!(freeme = malloc(freeme_sz, M_PFKEY, M_NOWAIT | M_ZERO))) {
}
/* Keep track what this socket has registered for */
- s = keylock(kp);
+ keylock(kp);
kp->kcb_reg |=
(1 << ((struct sadb_msg *)message)->sadb_msg_satype);
- keyunlock(kp, s);
+ keyunlock(kp);
ssup = (struct sadb_supported *) freeme2;
ssup->sadb_supported_len = freeme2_sz / sizeof(uint64_t);
if (!smsg->sadb_msg_seq ||
(smsg->sadb_msg_seq == kp->kcb_pid)) {
- s = keylock(bkp);
+ keylock(bkp);
pfkey_sendup(bkp, packet, 1);
- keyunlock(bkp, s);
+ keyunlock(bkp);
}
}
SRPL_LEAVE(&sr);
goto ret;
}
- s = keylock(kp);
+ keylock(kp);
i = (kp->kcb_flags &
PFKEYV2_SOCKETFLAGS_PROMISC) ? 1 : 0;
j = smsg->sadb_msg_satype ? 1 : 0;
mtx_leave(&pfkeyv2_mtx);
}
}
- keyunlock(kp, s);
+ keyunlock(kp);
}
break;
-/* $OpenBSD: rtsock.c,v 1.327 2022/03/09 17:29:52 claudio Exp $ */
+/* $OpenBSD: rtsock.c,v 1.328 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
rop_list);
rw_exit(&rtptable.rtp_lk);
- sounlock(so, SL_LOCKED);
+ sounlock(so);
/* wait for all references to drop */
refcnt_finalize(&rop->rop_refcnt, "rtsockrefs");
rtm_senddesync_timer(void *xso)
{
struct socket *so = xso;
- int s;
- s = solock(so);
+ solock(so);
rtm_senddesync(so);
- sounlock(so, s);
+ sounlock(so);
}
void
struct rt_msghdr *rtm;
struct mbuf *m = m0;
struct srp_ref sr;
- int s;
/* ensure that we can access the rtm_type via mtod() */
if (m->m_len < offsetof(struct rt_msghdr, rtm_type) + 1) {
so = rop->rop_socket;
- s = solock(so);
+ solock(so);
/*
* Check to see if we don't want our own messages and
rtm_sendup(so, m);
next:
- sounlock(so, s);
+ sounlock(so);
}
SRPL_LEAVE(&sr);
* descriptor reference is still held.
*/
- sounlock(so, SL_LOCKED);
+ sounlock(so);
len = m->m_pkthdr.len;
if (len < offsetof(struct rt_msghdr, rtm_hdrlen) + 1 ||
-/* $OpenBSD: in_pcb.c,v 1.266 2022/05/15 09:12:20 dlg Exp $ */
+/* $OpenBSD: in_pcb.c,v 1.267 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */
/*
* sockets, do not release it to not introduce new sleeping
* points.
*/
- sofree(so, SL_NOUNLOCK);
+ sofree(so, 1);
m_freem(inp->inp_options);
if (inp->inp_route.ro_rt) {
rtfree(inp->inp_route.ro_rt);
-/* $OpenBSD: krpc_subr.c,v 1.36 2019/01/22 22:45:04 bluhm Exp $ */
+/* $OpenBSD: krpc_subr.c,v 1.37 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: krpc_subr.c,v 1.12.4.1 1996/06/07 00:52:26 cgd Exp $ */
/*
struct rpc_call *call;
struct rpc_reply *reply;
struct uio auio;
- int s, error, rcvflg, timo, secs, len, authlen;
+ int error, rcvflg, timo, secs, len, authlen;
static u_int32_t xid = 0;
char addr[INET_ADDRSTRLEN];
int *ip;
tv.tv_usec = 0;
memcpy(mtod(m, struct timeval *), &tv, sizeof tv);
m->m_len = sizeof(tv);
- s = solock(so);
+ solock(so);
error = sosetopt(so, SOL_SOCKET, SO_RCVTIMEO, m);
- sounlock(so, s);
+ sounlock(so);
m_freem(m);
if (error)
goto out;
on = mtod(m, int32_t *);
m->m_len = sizeof(*on);
*on = 1;
- s = solock(so);
+ solock(so);
error = sosetopt(so, SOL_SOCKET, SO_BROADCAST, m);
- sounlock(so, s);
+ sounlock(so);
m_freem(m);
if (error)
goto out;
mopt->m_len = sizeof(int);
ip = mtod(mopt, int *);
*ip = IP_PORTRANGE_LOW;
- s = solock(so);
+ solock(so);
error = sosetopt(so, IPPROTO_IP, IP_PORTRANGE, mopt);
- sounlock(so, s);
+ sounlock(so);
m_freem(mopt);
if (error)
goto out;
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = INADDR_ANY;
sin->sin_port = htons(0);
- s = solock(so);
+ solock(so);
error = sobind(so, m, &proc0);
- sounlock(so, s);
+ sounlock(so);
m_freem(m);
if (error) {
printf("bind failed\n");
mopt->m_len = sizeof(int);
ip = mtod(mopt, int *);
*ip = IP_PORTRANGE_DEFAULT;
- s = solock(so);
+ solock(so);
error = sosetopt(so, IPPROTO_IP, IP_PORTRANGE, mopt);
- sounlock(so, s);
+ sounlock(so);
m_freem(mopt);
if (error)
goto out;
-/* $OpenBSD: nfs_socket.c,v 1.141 2022/05/22 04:52:17 visa Exp $ */
+/* $OpenBSD: nfs_socket.c,v 1.142 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: nfs_socket.c,v 1.27 1996/04/15 20:20:00 thorpej Exp $ */
/*
nfs_connect(struct nfsmount *nmp, struct nfsreq *rep)
{
struct socket *so;
- int s, error, rcvreserve, sndreserve;
+ int error, rcvreserve, sndreserve;
struct sockaddr *saddr;
struct sockaddr_in *sin;
struct mbuf *nam = NULL, *mopt = NULL;
MGET(nam, M_WAIT, MT_SONAME);
so = nmp->nm_so;
- s = solock(so);
+ solock(so);
nmp->nm_soflags = so->so_proto->pr_flags;
/*
goto bad;
so->so_rcv.sb_flags |= SB_NOINTR;
so->so_snd.sb_flags |= SB_NOINTR;
- sounlock(so, s);
+ sounlock(so);
m_freem(mopt);
m_freem(nam);
return (0);
bad:
- sounlock(so, s);
+ sounlock(so);
m_freem(mopt);
m_freem(nam);
-/* $OpenBSD: nfs_syscalls.c,v 1.117 2021/03/11 13:31:35 jsg Exp $ */
+/* $OpenBSD: nfs_syscalls.c,v 1.118 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: nfs_syscalls.c,v 1.19 1996/02/18 11:53:52 fvdl Exp $ */
/*
struct nfssvc_sock *slp;
struct socket *so;
struct nfssvc_sock *tslp;
- int s, error;
+ int error;
so = (struct socket *)fp->f_data;
tslp = NULL;
siz = NFS_MAXPACKET + sizeof (u_long);
else
siz = NFS_MAXPACKET;
- s = solock(so);
+ solock(so);
error = soreserve(so, siz, siz);
if (error) {
- sounlock(so, s);
+ sounlock(so);
m_freem(mynam);
return (error);
}
so->so_rcv.sb_timeo_nsecs = INFSLP;
so->so_snd.sb_flags &= ~SB_NOINTR;
so->so_snd.sb_timeo_nsecs = INFSLP;
- sounlock(so, s);
+ sounlock(so);
if (tslp)
slp = tslp;
else {
-/* $OpenBSD: socketvar.h,v 1.101 2021/11/06 05:26:33 visa Exp $ */
+/* $OpenBSD: socketvar.h,v 1.102 2022/06/06 14:45:41 claudio Exp $ */
/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */
/*-
#include <lib/libkern/libkern.h>
-/*
- * Values for sounlock()/sofree().
- */
-#define SL_NOUNLOCK 0x00
-#define SL_LOCKED 0x42
-
void soassertlocked(struct socket *);
/*
int sockargs(struct mbuf **, const void *, size_t, int);
int sosleep_nsec(struct socket *, void *, int, const char *, uint64_t);
-int solock(struct socket *);
-void sounlock(struct socket *, int);
+void solock(struct socket *);
+void sounlock(struct socket *);
int sendit(struct proc *, int, struct msghdr *, int, register_t *);
int recvit(struct proc *, int, struct msghdr *, caddr_t, register_t *);