summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2022-02-25 08:36:02 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2022-02-25 08:36:02 +0000
commit8238d29934c502864bde6a443ec0477043c6bba5 (patch)
tree0209ea9e5a21710204de93312ec9aa9af413decf /sys/kern
parentd73b76e55d5db7e118c36225e527630ec207c4ff (diff)
Move pr_attach and pr_detach to a new structure pr_usrreqs that can
then be shared among protosw structures, following the same basic direction as NetBSD and FreeBSD for this. Split PRU_CONTROL out of pr_usrreq into pru_control, giving it the proper prototype to eliminate the previously necessary casts. ok mvs@ bluhm@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/sys_socket.c8
-rw-r--r--sys/kern/uipc_proto.c11
-rw-r--r--sys/kern/uipc_socket.c10
-rw-r--r--sys/kern/uipc_socket2.c6
-rw-r--r--sys/kern/uipc_usrreq.c9
5 files changed, 23 insertions, 21 deletions
diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c
index 103ee79ca6a..e6cae385d4b 100644
--- a/sys/kern/sys_socket.c
+++ b/sys/kern/sys_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_socket.c,v 1.47 2021/10/24 00:02:25 jsg Exp $ */
+/* $OpenBSD: sys_socket.c,v 1.48 2022/02/25 08:36:01 guenther Exp $ */
/* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */
/*
@@ -139,9 +139,11 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
}
if (IOCGROUP(cmd) == 'r')
return (EOPNOTSUPP);
+ if (so->so_proto->pr_usrreqs->pru_control == NULL)
+ return (EOPNOTSUPP);
KERNEL_LOCK();
- error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
- (struct mbuf *)cmd, (struct mbuf *)data, NULL, p));
+ error = ((*so->so_proto->pr_usrreqs->pru_control)(so, cmd,
+ data, NULL));
KERNEL_UNLOCK();
break;
}
diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c
index 8ec85a32169..c0d9d6f989e 100644
--- a/sys/kern/uipc_proto.c
+++ b/sys/kern/uipc_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_proto.c,v 1.20 2021/05/30 21:01:27 bluhm Exp $ */
+/* $OpenBSD: uipc_proto.c,v 1.21 2022/02/25 08:36:01 guenther Exp $ */
/* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */
/*-
@@ -51,8 +51,7 @@ const struct protosw unixsw[] = {
.pr_protocol = PF_UNIX,
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
- .pr_attach = uipc_attach,
- .pr_detach = uipc_detach,
+ .pr_usrreqs = &uipc_usrreqs,
},
{
.pr_type = SOCK_SEQPACKET,
@@ -60,8 +59,7 @@ const struct protosw unixsw[] = {
.pr_protocol = PF_UNIX,
.pr_flags = PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
- .pr_attach = uipc_attach,
- .pr_detach = uipc_detach,
+ .pr_usrreqs = &uipc_usrreqs,
},
{
.pr_type = SOCK_DGRAM,
@@ -69,8 +67,7 @@ const struct protosw unixsw[] = {
.pr_protocol = PF_UNIX,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
- .pr_attach = uipc_attach,
- .pr_detach = uipc_detach,
+ .pr_usrreqs = &uipc_usrreqs,
}
};
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index d294b4df857..084f9c44edc 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket.c,v 1.273 2022/02/16 13:16:10 visa Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.274 2022/02/25 08:36:01 guenther Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@@ -169,7 +169,7 @@ socreate(int dom, struct socket **aso, int type, int proto)
prp = pffindproto(dom, proto, type);
else
prp = pffindtype(dom, type);
- if (prp == NULL || prp->pr_attach == NULL)
+ if (prp == NULL || prp->pr_usrreqs->pru_attach == NULL)
return (EPROTONOSUPPORT);
if (prp->pr_type != type)
return (EPROTOTYPE);
@@ -192,7 +192,7 @@ socreate(int dom, struct socket **aso, int type, int proto)
so->so_rcv.sb_timeo_nsecs = INFSLP;
s = solock(so);
- error = (*prp->pr_attach)(so, proto);
+ error = (*prp->pr_usrreqs->pru_attach)(so, proto);
if (error) {
so->so_state |= SS_NOFDREF;
/* sofree() calls sounlock(). */
@@ -347,8 +347,8 @@ soclose(struct socket *so, int flags)
drop:
if (so->so_pcb) {
int error2;
- KASSERT(so->so_proto->pr_detach);
- error2 = (*so->so_proto->pr_detach)(so);
+ KASSERT(so->so_proto->pr_usrreqs->pru_detach != NULL);
+ error2 = (*so->so_proto->pr_usrreqs->pru_detach)(so);
if (error == 0)
error = error2;
}
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index df28d6f10e8..df506fd5ada 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket2.c,v 1.118 2022/02/21 12:09:15 jsg Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.119 2022/02/25 08:36:01 guenther Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
@@ -150,7 +150,7 @@ sonewconn(struct socket *head, int connstatus)
/*
* XXXSMP as long as `so' and `head' share the same lock, we
- * can call soreserve() and pr_attach() below w/o explicitly
+ * can call soreserve() and pru_attach() below w/o explicitly
* locking `so'.
*/
soassertlocked(head);
@@ -194,7 +194,7 @@ sonewconn(struct socket *head, int connstatus)
sigio_copy(&so->so_sigio, &head->so_sigio);
soqinsque(head, so, soqueue);
- if ((*so->so_proto->pr_attach)(so, 0)) {
+ if ((*so->so_proto->pr_usrreqs->pru_attach)(so, 0)) {
(void) soqremque(so, soqueue);
sigio_free(&so->so_sigio);
klist_free(&so->so_rcv.sb_sel.si_note);
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index dbb1845358f..a25bda5a765 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.161 2021/12/29 07:15:13 anton Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.162 2022/02/25 08:36:01 guenther Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -150,8 +150,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
struct socket *so2;
int error = 0;
- if (req == PRU_CONTROL)
- return (EOPNOTSUPP);
if (req != PRU_SEND && control && control->m_len) {
error = EOPNOTSUPP;
goto release;
@@ -472,6 +470,11 @@ uipc_detach(struct socket *so)
return (0);
}
+const struct pr_usrreqs uipc_usrreqs = {
+ .pru_attach = uipc_attach,
+ .pru_detach = uipc_detach,
+};
+
int
uipc_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
size_t newlen)