summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2017-03-13 20:18:21 +0000
committerclaudio <claudio@openbsd.org>2017-03-13 20:18:21 +0000
commit3d7f610ca455928a1a6266ec779dbfc0c033fe19 (patch)
tree38477a0682053bcaa34bd606f2a7d94c05b5153d /sys/kern
parentPrint title="..." in addition to id="..." attributes for macro keys (diff)
downloadwireguard-openbsd-3d7f610ca455928a1a6266ec779dbfc0c033fe19.tar.xz
wireguard-openbsd-3d7f610ca455928a1a6266ec779dbfc0c033fe19.zip
Move PRU_ATTACH out of the pr_usrreq functions into pr_attach.
Attach is quite a different thing to the other PRU functions and this should make locking a bit simpler. This also removes the ugly hack on how proto was passed to the attach function. OK bluhm@ and mpi@ on a previous version
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/uipc_proto.c5
-rw-r--r--sys/kern/uipc_socket.c8
-rw-r--r--sys/kern/uipc_socket2.c5
-rw-r--r--sys/kern/uipc_usrreq.c16
4 files changed, 15 insertions, 19 deletions
diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c
index e1965b3f1e8..1e86120f374 100644
--- a/sys/kern/uipc_proto.c
+++ b/sys/kern/uipc_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_proto.c,v 1.13 2017/03/02 08:58:24 mpi Exp $ */
+/* $OpenBSD: uipc_proto.c,v 1.14 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */
/*-
@@ -55,6 +55,7 @@ struct protosw unixsw[] = {
.pr_protocol = PF_LOCAL,
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
+ .pr_attach = uipc_attach,
},
{
.pr_type = SOCK_SEQPACKET,
@@ -62,6 +63,7 @@ struct protosw unixsw[] = {
.pr_protocol = PF_LOCAL,
.pr_flags = PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
+ .pr_attach = uipc_attach,
},
{
.pr_type = SOCK_DGRAM,
@@ -69,6 +71,7 @@ struct protosw unixsw[] = {
.pr_protocol = PF_LOCAL,
.pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS,
.pr_usrreq = uipc_usrreq,
+ .pr_attach = uipc_attach,
}
};
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 93162a4e256..1bb5874d1fa 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket.c,v 1.179 2017/03/07 09:23:27 mpi Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.180 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@@ -119,7 +119,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_usrreq == 0)
+ if (prp == NULL || prp->pr_attach == NULL)
return (EPROTONOSUPPORT);
if (prp->pr_type != type)
return (EPROTOTYPE);
@@ -135,9 +135,9 @@ socreate(int dom, struct socket **aso, int type, int proto)
so->so_egid = p->p_ucred->cr_gid;
so->so_cpid = p->p_p->ps_pid;
so->so_proto = prp;
+
s = solock(so);
- error = (*prp->pr_usrreq)(so, PRU_ATTACH, NULL,
- (struct mbuf *)(long)proto, NULL, p);
+ error = (*prp->pr_attach)(so, proto);
if (error) {
so->so_state |= SS_NOFDREF;
sofree(so);
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index aca06097411..2da9a6a61d6 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket2.c,v 1.73 2017/03/07 09:23:27 mpi Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.74 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
@@ -187,8 +187,7 @@ sonewconn(struct socket *head, int connstatus)
so->so_rcv.sb_timeo = head->so_rcv.sb_timeo;
soqinsque(head, so, soqueue);
- if ((*so->so_proto->pr_usrreq)(so, PRU_ATTACH, NULL, NULL, NULL,
- curproc)) {
+ if ((*so->so_proto->pr_attach)(so, 0)) {
(void) soqremque(so, soqueue);
pool_put(&socket_pool, so);
return (NULL);
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 01fee7121f8..9a6d192ac62 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.116 2017/02/14 09:46:21 mpi Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.117 2017/03/13 20:18:21 claudio Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -117,7 +117,7 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
error = EOPNOTSUPP;
goto release;
}
- if (unp == NULL && req != PRU_ATTACH) {
+ if (unp == NULL) {
error = EINVAL;
goto release;
}
@@ -126,14 +126,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
switch (req) {
- case PRU_ATTACH:
- if (unp) {
- error = EISCONN;
- break;
- }
- error = unp_attach(so);
- break;
-
case PRU_DETACH:
unp_detach(unp);
break;
@@ -351,11 +343,13 @@ u_long unpdg_recvspace = 4*1024;
int unp_rights; /* file descriptors in flight */
int
-unp_attach(struct socket *so)
+uipc_attach(struct socket *so, int proto)
{
struct unpcb *unp;
int error;
+ if (so->so_pcb)
+ return EISCONN;
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
switch (so->so_type) {