-/* $OpenBSD: sys_socket.c,v 1.51 2022/06/20 01:39:44 visa Exp $ */
+/* $OpenBSD: sys_socket.c,v 1.52 2022/08/13 21:01:46 mvs Exp $ */
/* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */
/*
if (IOCGROUP(cmd) == 'r')
return (EOPNOTSUPP);
KERNEL_LOCK();
- error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
- (struct mbuf *)cmd, (struct mbuf *)data, NULL, p));
+ error = pru_control(so, cmd, data, NULL, p);
KERNEL_UNLOCK();
break;
}
ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
ub->st_uid = so->so_euid;
ub->st_gid = so->so_egid;
- (void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
- (struct mbuf *)ub, NULL, NULL, p));
+ (void)pru_sense(so, ub);
sounlock(so);
return (0);
}
-/* $OpenBSD: uipc_socket.c,v 1.280 2022/07/25 07:28:22 visa Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.281 2022/08/13 21:01:46 mvs Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
so->so_rcv.sb_timeo_nsecs = INFSLP;
solock(so);
- error = (*prp->pr_attach)(so, proto);
+ error = pru_attach(so, proto);
if (error) {
so->so_state |= SS_NOFDREF;
/* sofree() calls sounlock(). */
int
sobind(struct socket *so, struct mbuf *nam, struct proc *p)
{
- int error;
-
soassertlocked(so);
-
- error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, NULL, nam, NULL, p);
- return (error);
+ return pru_bind(so, nam, p);
}
int
if (isspliced(so) || issplicedback(so))
return (EOPNOTSUPP);
#endif /* SOCKET_SPLICE */
- error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, NULL, NULL, NULL,
- curproc);
+ error = pru_listen(so);
if (error)
return (error);
if (TAILQ_FIRST(&so->so_q) == NULL)
drop:
if (so->so_pcb) {
int error2;
- KASSERT(so->so_proto->pr_detach);
- error2 = (*so->so_proto->pr_detach)(so);
+ error2 = pru_detach(so);
if (error == 0)
error = error2;
}
{
soassertlocked(so);
- return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, NULL, NULL, NULL,
- curproc);
+ return pru_abort(so);
}
int
so->so_state &= ~SS_NOFDREF;
if ((so->so_state & SS_ISDISCONNECTED) == 0 ||
(so->so_proto->pr_flags & PR_ABRTACPTDIS) == 0)
- error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, NULL,
- nam, NULL, curproc);
+ error = pru_accept(so, nam);
else
error = ECONNABORTED;
return (error);
(error = sodisconnect(so))))
error = EISCONN;
else
- error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT,
- NULL, nam, NULL, curproc);
+ error = pru_connect(so, nam);
return (error);
}
else
solock(so1);
- error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, NULL,
- (struct mbuf *)so2, NULL, curproc);
+ error = pru_connect2(so1, so2);
if (persocket)
sounlock(so2);
return (ENOTCONN);
if (so->so_state & SS_ISDISCONNECTING)
return (EALREADY);
- error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, NULL, NULL,
- NULL, curproc);
+ error = pru_disconnect(so);
return (error);
}
so->so_state &= ~SS_ISSENDING;
if (top && so->so_options & SO_ZEROIZE)
top->m_flags |= M_ZEROIZE;
- error = (*so->so_proto->pr_usrreq)(so,
- (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND,
- top, addr, control, curproc);
+ if (flags & MSG_OOB)
+ error = pru_sendoob(so, top, addr, control);
+ else
+ error = pru_send(so, top, addr, control);
clen = 0;
control = NULL;
top = NULL;
if (flags & MSG_OOB) {
m = m_get(M_WAIT, MT_DATA);
solock(so);
- error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m,
- (struct mbuf *)(long)(flags & MSG_PEEK), NULL, curproc);
+ error = pru_rcvoob(so, m, flags & MSG_PEEK);
sounlock(so);
if (error)
goto bad;
SBLASTRECORDCHK(&so->so_rcv, "soreceive 4");
SBLASTMBUFCHK(&so->so_rcv, "soreceive 4");
if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
- (*pr->pr_usrreq)(so, PRU_RCVD, NULL,
- (struct mbuf *)(long)flags, NULL, curproc);
+ pru_rcvd(so, flags);
}
if (orig_resid == uio->uio_resid && orig_resid &&
(flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
int
soshutdown(struct socket *so, int how)
{
- const struct protosw *pr = so->so_proto;
int error = 0;
solock(so);
sorflush(so);
/* FALLTHROUGH */
case SHUT_WR:
- error = (*pr->pr_usrreq)(so, PRU_SHUTDOWN, NULL, NULL, NULL,
- curproc);
+ error = pru_shutdown(so);
break;
default:
error = EINVAL;
if (m == NULL) {
sbdroprecord(so, &so->so_rcv);
if (so->so_proto->pr_flags & PR_WANTRCVD && so->so_pcb)
- (so->so_proto->pr_usrreq)(so, PRU_RCVD, NULL,
- NULL, NULL, NULL);
+ pru_rcvd(so, 0);
goto nextpkt;
}
/* Send window update to source peer as receive buffer has changed. */
if (so->so_proto->pr_flags & PR_WANTRCVD && so->so_pcb)
- (so->so_proto->pr_usrreq)(so, PRU_RCVD, NULL,
- NULL, NULL, NULL);
+ pru_rcvd(so, 0);
/* Receive buffer did shrink by len bytes, adjust oob. */
state = so->so_state;
} else if (oobmark) {
o = m_split(m, oobmark, wait);
if (o) {
- error = (*sosp->so_proto->pr_usrreq)(sosp,
- PRU_SEND, m, NULL, NULL, NULL);
+ error = pru_send(sosp, m, NULL, NULL);
if (error) {
if (sosp->so_state & SS_CANTSENDMORE)
error = EPIPE;
if (o) {
o->m_len = 1;
*mtod(o, caddr_t) = *mtod(m, caddr_t);
- error = (*sosp->so_proto->pr_usrreq)(sosp, PRU_SENDOOB,
- o, NULL, NULL, NULL);
+ error = pru_sendoob(sosp, o, NULL, NULL);
if (error) {
if (sosp->so_state & SS_CANTSENDMORE)
error = EPIPE;
/* Append all remaining data to drain socket. */
if (so->so_rcv.sb_cc == 0 || maxreached)
sosp->so_state &= ~SS_ISSENDING;
- error = (*sosp->so_proto->pr_usrreq)(sosp, PRU_SEND, m, NULL, NULL,
- NULL);
+ error = pru_send(sosp, m, NULL, NULL);
if (error) {
if (sosp->so_state & SS_CANTSENDMORE)
error = EPIPE;
-/* $OpenBSD: uipc_socket2.c,v 1.126 2022/07/25 07:28:22 visa Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.127 2022/08/13 21:01:46 mvs Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
sounlock(head);
}
- error = (*so->so_proto->pr_attach)(so, 0);
+ error = pru_attach(so, 0);
if (persocket) {
sounlock(so);
-/* $OpenBSD: uipc_syscalls.c,v 1.199 2022/07/18 04:42:37 deraadt Exp $ */
+/* $OpenBSD: uipc_syscalls.c,v 1.200 2022/08/13 21:01:46 mvs Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */
/*
}
m = m_getclr(M_WAIT, MT_SONAME);
solock(so);
- error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, NULL, m, NULL, p);
+ error = pru_sockaddr(so, m);
sounlock(so);
if (error)
goto bad;
goto bad;
m = m_getclr(M_WAIT, MT_SONAME);
solock(so);
- error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, NULL, m, NULL, p);
+ error = pru_peeraddr(so, m);
sounlock(so);
if (error)
goto bad;
-/* $OpenBSD: if.c,v 1.662 2022/08/06 15:57:58 bluhm Exp $ */
+/* $OpenBSD: if.c,v 1.663 2022/08/13 21:01:46 mvs Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
break;
/* FALLTHROUGH */
default:
- error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
- (struct mbuf *) cmd, (struct mbuf *) data,
- (struct mbuf *) ifp, p));
+ error = pru_control(so, cmd, data, ifp, p);
if (error != EOPNOTSUPP)
break;
switch (cmd) {
-/* $OpenBSD: nfs_socket.c,v 1.142 2022/06/06 14:45:41 claudio Exp $ */
+/* $OpenBSD: nfs_socket.c,v 1.143 2022/08/13 21:01:46 mvs Exp $ */
/* $NetBSD: nfs_socket.c,v 1.27 1996/04/15 20:20:00 thorpej Exp $ */
/*
nmp->nm_sent < nmp->nm_cwnd) &&
(m = m_copym(rep->r_mreq, 0, M_COPYALL, M_DONTWAIT))){
if ((nmp->nm_flag & NFSMNT_NOCONN) == 0)
- error = (*so->so_proto->pr_usrreq)(so, PRU_SEND,
- m, NULL, NULL, curproc);
+ error = pru_send(so, m, NULL, NULL);
else
- error = (*so->so_proto->pr_usrreq)(so, PRU_SEND,
- m, nmp->nm_nam, NULL, curproc);
+ error = pru_send(so, m, nmp->nm_nam, NULL);
if (error) {
if (NFSIGNORE_SOERROR(nmp->nm_soflags, error))
so->so_error = 0;
-/* $OpenBSD: protosw.h,v 1.35 2022/02/25 23:51:04 guenther Exp $ */
+/* $OpenBSD: protosw.h,v 1.36 2022/08/13 21:01:46 mvs Exp $ */
/* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */
/*-
#endif
#ifdef _KERNEL
+
+#include <sys/socketvar.h>
+#include <sys/systm.h>
+
+struct ifnet;
struct sockaddr;
const struct protosw *pffindproto(int, int, int);
const struct protosw *pffindtype(int, int);
extern const struct protosw inet6sw[];
#endif /* INET6 */
+static inline int
+pru_attach(struct socket *so, int proto)
+{
+ return (*so->so_proto->pr_attach)(so, proto);
+}
+
+static inline int
+pru_detach(struct socket *so)
+{
+ return (*so->so_proto->pr_detach)(so);
+}
+
+static inline int
+pru_bind(struct socket *so, struct mbuf *nam, struct proc *p)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_BIND, NULL, nam, NULL, p);
+}
+
+static inline int
+pru_listen(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_LISTEN, NULL, NULL, NULL, curproc);
+}
+
+static inline int
+pru_connect(struct socket *so, struct mbuf *nam)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_CONNECT, NULL, nam, NULL, curproc);
+}
+
+static inline int
+pru_accept(struct socket *so, struct mbuf *nam)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_ACCEPT, NULL, nam, NULL, curproc);
+}
+
+static inline int
+pru_disconnect(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_DISCONNECT, NULL, NULL, NULL, curproc);
+}
+
+static inline int
+pru_shutdown(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_SHUTDOWN, NULL, NULL, NULL, curproc);
+}
+
+static inline int
+pru_rcvd(struct socket *so, int flags)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_RCVD, NULL, (struct mbuf *)(long)flags, NULL, curproc);
+}
+
+static inline int
+pru_send(struct socket *so, struct mbuf *top, struct mbuf *addr,
+ struct mbuf *control)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_SEND, top, addr, control, curproc);
+}
+
+static inline int
+pru_abort(struct socket *so)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_ABORT, NULL, NULL, NULL, curproc);
+}
+
+static inline int
+pru_control(struct socket *so, u_long cmd, caddr_t data,
+ struct ifnet *ifp, struct proc *p)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_CONTROL, (struct mbuf *)cmd, (struct mbuf *)data,
+ (struct mbuf *)ifp, p);
+}
+
+static inline int
+pru_sense(struct socket *so, struct stat *ub)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_SENSE, (struct mbuf *)ub, NULL, NULL, curproc);
+}
+
+static inline int
+pru_rcvoob(struct socket *so, struct mbuf *m, int flags)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_RCVOOB, m, (struct mbuf *)(long)flags, NULL, curproc);
+}
+
+static inline int
+pru_sendoob(struct socket *so, struct mbuf *top, struct mbuf *addr,
+ struct mbuf *control)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_SENDOOB, top, addr, control, curproc);
+}
+
+static inline int
+pru_sockaddr(struct socket *so, struct mbuf *addr)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_SOCKADDR, NULL, addr, NULL, curproc);
+}
+
+static inline int
+pru_peeraddr(struct socket *so, struct mbuf *addr)
+{
+ return (*so->so_proto->pr_usrreq)(so,
+ PRU_PEERADDR, NULL, addr, NULL, curproc);
+}
+
+static inline int
+pru_connect2(struct socket *so1, struct socket *so2)
+{
+ return (*so1->so_proto->pr_usrreq)(so1,
+ PRU_CONNECT2, NULL, (struct mbuf *)so2, NULL, curproc);
+}
+
#endif
-/* $OpenBSD: socketvar.h,v 1.106 2022/07/15 17:20:24 deraadt Exp $ */
+/* $OpenBSD: socketvar.h,v 1.107 2022/08/13 21:01:46 mvs Exp $ */
/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */
/*-
* @(#)socketvar.h 8.1 (Berkeley) 6/2/93
*/
+#ifndef _SYS_SOCKETVAR_H_
+#define _SYS_SOCKETVAR_H_
+
#include <sys/selinfo.h> /* for struct selinfo */
#include <sys/queue.h>
#include <sys/sigio.h> /* for struct sigio_ref */
#endif /* SOCKBUF_DEBUG */
#endif /* _KERNEL */
+
+#endif /* _SYS_SOCKETVAR_H_ */